<div dir="ltr"><div dir="ltr"><div><div>From 566d10f864a9b6aee43de9148be203af6cbfb656 Mon Sep 17 00:00:00 2001</div><div>From: Karam Singh <<a href="mailto:karam.singh@multicorewareinc.com">karam.singh@multicorewareinc.com</a>></div><div>Date: Tue, 18 Jul 2023 17:48:32 +0530</div><div>Subject: [PATCH] Fix in zonefile parameter reflection in Lookahead analysis</div><div><br></div><div>---</div><div> source/encoder/slicetype.cpp | 42 ++++++++++++++++++++----------------</div><div> 1 file changed, 23 insertions(+), 19 deletions(-)</div><div><br></div><div>diff --git a/source/encoder/slicetype.cpp b/source/encoder/slicetype.cpp</div><div>index 8e67c2ed4..f478f3282 100644</div><div>--- a/source/encoder/slicetype.cpp</div><div>+++ b/source/encoder/slicetype.cpp</div><div>@@ -1359,32 +1359,32 @@ void Lookahead::getEstimatedPictureCost(Frame *curFrame)</div><div>     default:</div><div>         return;</div><div>     }</div><div>-    if (!m_param->analysisLoad || !m_param->bDisableLookahead)</div><div>+    if (!curFrame->m_param->analysisLoad || !curFrame->m_param->bDisableLookahead)</div><div>     {</div><div>         X265_CHECK(curFrame->m_lowres.costEst[b - p0][p1 - b] > 0, "Slice cost not estimated\n")</div><div> </div><div>-        if (m_param->rc.cuTree && !m_param->rc.bStatRead)</div><div>+        if (curFrame->m_param->rc.cuTree && !curFrame->m_param->rc.bStatRead)</div><div>             /* update row satds based on cutree offsets */</div><div>             curFrame->m_lowres.satdCost = frameCostRecalculate(frames, p0, p1, b);</div><div>-        else if (!m_param->analysisLoad || m_param->scaleFactor || m_param->bAnalysisType == HEVC_INFO)</div><div>+        else if (!curFrame->m_param->analysisLoad || curFrame->m_param->scaleFactor || curFrame->m_param->bAnalysisType == HEVC_INFO)</div><div>         {</div><div>-            if (m_param->rc.aqMode)</div><div>+            if (curFrame->m_param->rc.aqMode)</div><div>                 curFrame->m_lowres.satdCost = curFrame->m_lowres.costEstAq[b - p0][p1 - b];</div><div>             else</div><div>                 curFrame->m_lowres.satdCost = curFrame->m_lowres.costEst[b - p0][p1 - b];</div><div>         }</div><div>-        if (m_param->rc.vbvBufferSize && m_param->rc.vbvMaxBitrate)</div><div>+        if (curFrame->m_param->rc.vbvBufferSize && curFrame->m_param->rc.vbvMaxBitrate)</div><div>         {</div><div>             /* aggregate lowres row satds to CTU resolution */</div><div>             curFrame->m_lowres.lowresCostForRc = curFrame->m_lowres.lowresCosts[b - p0][p1 - b];</div><div>             uint32_t lowresRow = 0, lowresCol = 0, lowresCuIdx = 0, sum = 0, intraSum = 0;</div><div>-            uint32_t scale = m_param->maxCUSize / (2 * X265_LOWRES_CU_SIZE);</div><div>-            uint32_t numCuInHeight = (m_param->sourceHeight + m_param->maxCUSize - 1) / m_param->maxCUSize;</div><div>+            uint32_t scale = curFrame->m_param->maxCUSize / (2 * X265_LOWRES_CU_SIZE);</div><div>+            uint32_t numCuInHeight = (curFrame->m_param->sourceHeight + curFrame->m_param->maxCUSize - 1) / curFrame->m_param->maxCUSize;</div><div>             uint32_t widthInLowresCu = (uint32_t)m_8x8Width, heightInLowresCu = (uint32_t)m_8x8Height;</div><div>             double *qp_offset = 0;</div><div>             /* Factor in qpoffsets based on Aq/Cutree in CU costs */</div><div>-            if (m_param->rc.aqMode || m_param->bAQMotion)</div><div>-                qp_offset = (frames[b]->sliceType == X265_TYPE_B || !m_param->rc.cuTree) ? frames[b]->qpAqOffset : frames[b]->qpCuTreeOffset;</div><div>+            if (curFrame->m_param->rc.aqMode || curFrame->m_param->bAQMotion)</div><div>+                qp_offset = (frames[b]->sliceType == X265_TYPE_B || !curFrame->m_param->rc.cuTree) ? frames[b]->qpAqOffset : frames[b]->qpCuTreeOffset;</div><div> </div><div>             for (uint32_t row = 0; row < numCuInHeight; row++)</div><div>             {</div><div>@@ -1400,7 +1400,7 @@ void Lookahead::getEstimatedPictureCost(Frame *curFrame)</div><div>                         if (qp_offset)</div><div>                         {</div><div>                             double qpOffset;</div><div>-                            if (m_param->rc.qgSize == 8)</div><div>+                            if (curFrame->m_param->rc.qgSize == 8)</div><div>                                 qpOffset = (qp_offset[lowresCol * 2 + lowresRow * widthInLowresCu * 4] +</div><div>                                 qp_offset[lowresCol * 2 + lowresRow * widthInLowresCu * 4 + 1] +</div><div>                                 qp_offset[lowresCol * 2 + lowresRow * widthInLowresCu * 4 + curFrame->m_lowres.maxBlocksInRowFullRes] +</div><div>@@ -1411,7 +1411,7 @@ void Lookahead::getEstimatedPictureCost(Frame *curFrame)</div><div>                             int32_t intraCuCost = curFrame->m_lowres.intraCost[lowresCuIdx];</div><div>                             curFrame->m_lowres.intraCost[lowresCuIdx] = (intraCuCost * x265_exp2fix8(qpOffset) + 128) >> 8;</div><div>                         }</div><div>-                        if (m_param->bIntraRefresh && slice->m_sliceType == X265_TYPE_P)</div><div>+                        if (curFrame->m_param->bIntraRefresh && slice->m_sliceType == X265_TYPE_P)</div><div>                             for (uint32_t x = curFrame->m_encData->m_pir.pirStartCol; x <= curFrame->m_encData->m_pir.pirEndCol; x++)</div><div>                                 diff += curFrame->m_lowres.intraCost[lowresCuIdx] - lowresCuCost;</div><div>                         curFrame->m_lowres.lowresCostForRc[lowresCuIdx] = lowresCuCost;</div><div>@@ -1802,15 +1802,19 @@ void Lookahead::slicetypeDecide()</div><div>         ScopedLock lock(m_inputLock);</div><div> </div><div>         Frame *curFrame = m_inputQueue.first();</div><div>+        if (m_param->bResetZoneConfig)</div><div>+        {</div><div>+            for (int i = 0; i < m_param->rc.zonefileCount; i++)</div><div>+            {</div><div>+                if (m_param->rc.zones[i].startFrame == curFrame->m_poc)</div><div>+                    m_param = m_param->rc.zones[i].zoneParam;</div><div>+                int nextZoneStart = m_param->rc.zones[i].startFrame;</div><div>+                nextZoneStart += nextZoneStart ? m_param->rc.zones[i].zoneParam->radl : 0;</div><div>+                if (nextZoneStart < curFrame->m_poc + maxSearch && curFrame->m_poc < nextZoneStart)</div><div>+                    maxSearch = nextZoneStart - curFrame->m_poc;</div><div>+            }</div><div>+        }</div><div>         int j;</div><div>-<span style="white-space:pre">              </span>if (m_param->bResetZoneConfig)</div><div>-<span style="white-space:pre">            </span>{</div><div>-<span style="white-space:pre">                    </span>for (int i = 0; i < m_param->rc.zonefileCount; i++)</div><div>-<span style="white-space:pre">                    </span>{</div><div>-<span style="white-space:pre">                            </span>if (m_param->rc.zones[i].startFrame == curFrame->m_poc)</div><div>-<span style="white-space:pre">                                        </span>m_param = m_param->rc.zones[i].zoneParam;</div><div>-<span style="white-space:pre">                 </span>}</div><div>-<span style="white-space:pre">            </span>}</div><div>         for (j = 0; j < m_param->bframes + 2; j++)</div><div>         {</div><div>             if (!curFrame) break;</div><div>-- </div><div>2.36.0.windows.1</div><div><br></div></div><div><br></div><br clear="all"><div><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>Karam Singh</div>Senior Video Codec Engineer<div>MulticoreWare, India</div></div></div></div></div></div>