<div dir="ltr">Hi Aruna,<div><br></div><div>I have reviewed the patch internally. Could you please review it once and push this patch to the default of x265?</div><div><br></div><div>Thanks,</div><div>Praveen</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jan 22, 2021 at 4:52 PM Niranjan Bala <<a href="mailto:niranjan@multicorewareinc.com">niranjan@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">From 64a985847ecca1a6937fe1dae00d3db79cf0bcb2 Mon Sep 17 00:00:00 2001<br>From: Niranjan <<a href="mailto:niranjan@multicorewareinc.com" target="_blank">niranjan@multicorewareinc.com</a>><br>Date: Fri, 22 Jan 2021 08:26:58 +0530<br>Subject: [PATCH] Fix: Hang when vbv is used with slices<br><br>---<br> source/encoder/frameencoder.cpp | 30 ++++++++++++++++--------------<br> source/encoder/frameencoder.h   |  4 ++--<br> 2 files changed, 18 insertions(+), 16 deletions(-)<br><br>diff --git a/source/encoder/frameencoder.cpp b/source/encoder/frameencoder.cpp<br>index 2086a15a5..efe85282f 100644<br>--- a/source/encoder/frameencoder.cpp<br>+++ b/source/encoder/frameencoder.cpp<br>@@ -47,8 +47,6 @@ FrameEncoder::FrameEncoder()<br>     m_slicetypeWaitTime = 0;<br>     m_activeWorkerCount = 0;<br>     m_completionCount = 0;<br>-    m_bAllRowsStop = false;<br>-    m_vbvResetTriggerRow = -1;<br>     m_outStreams = NULL;<br>     m_backupStreams = NULL;<br>     m_substreamSizes = NULL;<br>@@ -88,6 +86,8 @@ void FrameEncoder::destroy()<br>     delete[] m_outStreams;<br>     delete[] m_backupStreams;<br>     X265_FREE(m_sliceBaseRow);<br>+    X265_FREE((void*)m_bAllRowsStop);<br>+    X265_FREE((void*)m_vbvResetTriggerRow);<br>     X265_FREE(m_sliceMaxBlockRow);<br>     X265_FREE(m_cuGeoms);<br>     X265_FREE(m_ctuGeomMap);<br>@@ -118,6 +118,8 @@ bool FrameEncoder::init(Encoder *top, int numRows, int numCols)<br>     bool ok = !!m_numRows;<br> <br>     m_sliceBaseRow = X265_MALLOC(uint32_t, m_param->maxSlices + 1);<br>+    m_bAllRowsStop = X265_MALLOC(bool, m_param->maxSlices);<br>+    m_vbvResetTriggerRow = X265_MALLOC(int, m_param->maxSlices);<br>     ok &= !!m_sliceBaseRow;<br>     m_sliceGroupSize = (uint16_t)(m_numRows + m_param->maxSlices - 1) / m_param->maxSlices;<br>     uint32_t sliceGroupSizeAccu = (m_numRows << 8) / m_param->maxSlices;    <br>@@ -438,8 +440,8 @@ void FrameEncoder::compressFrame()<br>     m_stallStartTime = 0;<br> <br>     m_completionCount = 0;<br>-    m_bAllRowsStop = false;<br>-    m_vbvResetTriggerRow = -1;<br>+    memset((void*)m_bAllRowsStop, 0, sizeof(bool) * m_param->maxSlices);<br>+    memset((void*)m_vbvResetTriggerRow, -1, sizeof(int) * m_param->maxSlices);<br>     m_rowSliceTotalBits[0] = 0;<br>     m_rowSliceTotalBits[1] = 0;<br> <br>@@ -1469,16 +1471,16 @@ void FrameEncoder::processRowEncoder(int intRow, ThreadLocalData& tld)<br>                 curRow.bufferedEntropy.copyState(rowCoder);<br>                 curRow.bufferedEntropy.loadContexts(rowCoder);<br>             }<br>-            if (bFirstRowInSlice && m_vbvResetTriggerRow != intRow)            <br>+            if (bFirstRowInSlice && m_vbvResetTriggerRow[curRow.sliceId] != intRow)<br>             {<br>                 curEncData.m_rowStat[row].rowQp = curEncData.m_avgQpRc;<br>                 curEncData.m_rowStat[row].rowQpScale = x265_qp2qScale(curEncData.m_avgQpRc);<br>             }<br> <br>             FrameData::RCStatCU& cuStat = curEncData.m_cuStat[cuAddr];<br>-            if (m_param->bEnableWavefront && rowInSlice >= col && !bFirstRowInSlice && m_vbvResetTriggerRow != intRow)<br>+            if (m_param->bEnableWavefront && rowInSlice >= col && !bFirstRowInSlice && m_vbvResetTriggerRow[curRow.sliceId] != intRow)<br>                 cuStat.baseQp = curEncData.m_cuStat[cuAddr - numCols + 1].baseQp;<br>-            else if (!m_param->bEnableWavefront && !bFirstRowInSlice && m_vbvResetTriggerRow != intRow)<br>+            else if (!m_param->bEnableWavefront && !bFirstRowInSlice && m_vbvResetTriggerRow[curRow.sliceId] != intRow)<br>                 cuStat.baseQp = curEncData.m_rowStat[row - 1].rowQp;<br>             else<br>                 cuStat.baseQp = curEncData.m_rowStat[row].rowQp;<br>@@ -1655,7 +1657,7 @@ void FrameEncoder::processRowEncoder(int intRow, ThreadLocalData& tld)<br>                     x265_log(m_param, X265_LOG_DEBUG, "POC %d row %d - encode restart required for VBV, to %.2f from %.2f\n",<br>                         m_frame->m_poc, row, qpBase, curEncData.m_cuStat[cuAddr].baseQp);<br> <br>-                    m_vbvResetTriggerRow = row;<br>+                    m_vbvResetTriggerRow[curRow.sliceId] = row;<br>                     m_outStreams[0].copyBits(&m_backupStreams[0]);<br> <br>                     rowCoder.copyState(curRow.bufferedEntropy);<br>@@ -1707,8 +1709,8 @@ void FrameEncoder::processRowEncoder(int intRow, ThreadLocalData& tld)<br>                              m_frame->m_poc, row, qpBase, curEncData.m_cuStat[cuAddr].baseQp);<br> <br>                     // prevent the WaveFront::findJob() method from providing new jobs<br>-                    m_vbvResetTriggerRow = row;<br>-                    m_bAllRowsStop = true;<br>+                    m_vbvResetTriggerRow[curRow.sliceId] = row;<br>+                    m_bAllRowsStop[curRow.sliceId] = true;<br> <br>                     for (uint32_t r = m_sliceBaseRow[sliceId + 1] - 1; r >= row; r--)<br>                     {<br>@@ -1720,7 +1722,7 @@ void FrameEncoder::processRowEncoder(int intRow, ThreadLocalData& tld)<br>                             stopRow.lock.acquire();<br>                             while (stopRow.active)<br>                             {<br>-                                if (dequeueRow(r * 2))<br>+                                if (dequeueRow(m_row_to_idx[r] * 2))<br>                                     stopRow.active = false;<br>                                 else<br>                                 {<br>@@ -1758,13 +1760,13 @@ void FrameEncoder::processRowEncoder(int intRow, ThreadLocalData& tld)<br>                         curEncData.m_rowStat[r].sumQpAq = 0;<br>                     }<br> <br>-                    m_bAllRowsStop = false;<br>+                    m_bAllRowsStop[curRow.sliceId] = false;<br>                 }<br>             }<br>         }<br> <br>         if (m_param->bEnableWavefront && curRow.completed >= 2 && !bLastRowInSlice &&<br>-            (!m_bAllRowsStop || intRow + 1 < m_vbvResetTriggerRow))<br>+            (!m_bAllRowsStop[curRow.sliceId] || intRow + 1 < m_vbvResetTriggerRow[curRow.sliceId]))<br>         {<br>             /* activate next row */<br>             ScopedLock below(m_rows[row + 1].lock);<br>@@ -1779,7 +1781,7 @@ void FrameEncoder::processRowEncoder(int intRow, ThreadLocalData& tld)<br>         }<br> <br>         ScopedLock self(curRow.lock);<br>-        if ((m_bAllRowsStop && intRow > m_vbvResetTriggerRow) ||<br>+        if ((m_bAllRowsStop[curRow.sliceId] && intRow > m_vbvResetTriggerRow[curRow.sliceId]) ||<br>             (!bFirstRowInSlice && ((curRow.completed < numCols - 1) || (m_rows[row - 1].completed < numCols)) && m_rows[row - 1].completed < curRow.completed + 2))<br>         {<br>             curRow.active = false;<br>diff --git a/source/encoder/frameencoder.h b/source/encoder/frameencoder.h<br>index 668936872..f4cfc624d 100644<br>--- a/source/encoder/frameencoder.h<br>+++ b/source/encoder/frameencoder.h<br>@@ -140,9 +140,9 @@ public:<br>     int                      m_localTldIdx;<br>     bool                     m_reconfigure; /* reconfigure in progress */<br>     volatile bool            m_threadActive;<br>-    volatile bool            m_bAllRowsStop;<br>+    volatile bool            *m_bAllRowsStop;<br>     volatile int             m_completionCount;<br>-    volatile int             m_vbvResetTriggerRow;<br>+    volatile int             *m_vbvResetTriggerRow;<br>     volatile int             m_sliceCnt;<br> <br>     uint32_t                 m_numRows;<br>-- <br>2.18.0.windows.1<br><br><div><br></div>-- <br><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><font color="#0c343d" face="verdana, sans-serif"><br></font></div><div dir="ltr"><font color="#0c343d" face="verdana, sans-serif">Thanks & Regards</font><div><font color="#0c343d" face="verdana, sans-serif"><b>Niranjan Kumar B</b></font></div><div><font size="1" color="#0c343d" face="verdana, sans-serif">Video Codec Engineer </font></div><div><font size="1" color="#0c343d" face="verdana, sans-serif">Media & AI Analytics</font></div><div><font face="trebuchet ms, sans-serif" color="#0c343d">+91 958 511 1449</font></div><div><a href="https://multicorewareinc.com/" style="color:rgb(17,85,204)" target="_blank"><img src="https://docs.google.com/uc?export=download&id=1kc3RJu9M8bnIf6Xa5rUw2d-eEVUsPBE5&revid=0B7tw9XJBmynaemR1VUpQUi9DVytRVW5SVkRwVTFjb1hBMUcwPQ"></a></div></div></div></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>