<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Mar 11, 2014 at 2:51 AM, chen <span dir="ltr"><<a href="mailto:chenm003@163.com" target="_blank">chenm003@163.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="line-height:1.7;font-size:14px;font-family:arial">
<div class=""><div>>+ //block current row if previous row is getting reencoded or prev row reference cus are not completed.<br>>+ ScopedLock self(curRow.m_lock);<br>>+ if (row > 0 && (m_rows[row - 1].m_isReencode || m_rows[row].m_completed < numCols - 2 && m_rows[row - 1].m_completed < m_rows[row].m_completed + 2))<br>
>+ {<br>>+ m_rows[row].m_active = false;<br>>+ m_rows[row].m_busy = false;<br>>+ m_totalTime = m_totalTime + (x265_mdate() - startTime);<br>>+ return;<br>>+ }</div>
</div><div>Seems you use bottomRows to deactive row thread, but most thread will continue to work.</div>
<div>May we reset col to 0 for all rows below re-encode row.</div></div></blockquote><div><br></div><div>other Row threads will not be activated because, we block the scheduler in FindJobs() to early out till the flag <span style="font-family:arial,sans-serif;font-size:13px">m_bAllRowsStop is again set false. so until the current row restart again with col 0, the below rows still wait. If we set col to 0 here, for current active row, the for loop continue with col++ only.</span></div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="line-height:1.7;font-size:14px;font-family:arial">
<div><div class="h5">
<div><br>> for (uint32_t col = curRow.m_completed; col < numCols; col++)<br>> {<br>>+ //reset current row data if reencoded is turned on this row<br>>+ if (m_rows[row].m_isReencode == true )<br>
>+ {<br>>+ col = 0;<br>>+ m_bAllRowsStop = false;<br>>+ m_rows[row].m_isReencode = false; <br>>+ }<br>> const uint32_t cuAddr = lineStartCUAddr + col;<br>
> TComDataCU* cu = m_pic->getCU(cuAddr);<br>> cu->initCU(m_pic, cuAddr);<br>>@@ -1069,16 +1089,26 @@<br>> codeRow.m_entropyCoder.resetEntropy();<br>> TEncSbac *bufSbac = (m_cfg->param->bEnableWavefront && col == 0 && row > 0) ? &m_rows[row - 1].m_bufferSbacCoder : NULL;<br>
> <br>>- if ((uint32_t)row >= col && (row != 0) && isVbv)<br>>- qpBase = m_pic->getCU(cuAddr - numCols + 1)->m_baseQp;<br>>+ if(isVbv)<br>>+ {<br>>+ if ((uint32_t)row == 0)<br>
>+ m_pic->m_rowDiagQp[row] = m_pic->m_avgQpRc;<br>>+<br>>+ if ((uint32_t)row >= col && (row != 0) && m_vbvResetTriggerRow != row)<br>>+ cu->m_baseQp = m_pic->getCU(cuAddr - numCols + 1)->m_baseQp;<br>
>+ else <br>>+ cu->m_baseQp = m_pic->m_rowDiagQp[row];<br>>+ }<br>>+ else<br>>+ cu->m_baseQp = m_pic->m_avgQpRc;<br>> <br>> if (m_cfg->param->rc.aqMode || isVbv)<br>
> {<br>>- int qp = calcQpForCu(m_pic, cuAddr, qpBase);<br>>+ int qp = calcQpForCu(m_pic, cuAddr, cu->m_baseQp);<br>> setLambda(qp, row);<br>> qp = X265_MIN(qp, MAX_QP);<br>
> cu->setQP(0, char(qp));<br>>- cu->m_baseQp = qpBase;<br>>+<br>> if (m_cfg->param->rc.aqMode)<br>> m_pic->m_qpaAq[row] += qp;<br>> }<br>
>@@ -1087,22 +1117,46 @@<br>> {<br>> // Update encoded bits, satdCost, baseQP for each CU<br>> m_pic->m_rowDiagSatd[row] += m_pic->m_cuCostsForVbv[cuAddr];<br>>+ m_pic->m_rowDiagIntraSatd[row] += m_pic->m_intraCuCostsForVbv[cuAddr];<br>
> m_pic->m_rowEncodedBits[row] += cu->m_totalBits;<br>> m_pic->m_numEncodedCusPerRow[row] = cuAddr;<br>> m_pic->m_qpaRc[row] += cu->m_baseQp;<br>> <br>>- if ((uint32_t)row == col)<br>
>- m_pic->m_rowDiagQp[row] = qpBase;<br>>-<br>> // If current block is at row diagonal checkpoint, call vbv ratecontrol.<br>> if ((uint32_t)row == col && row != 0)<br>
> {<br>>- m_top->m_rateControl->rowDiagonalVbvRateControl(m_pic, row, &m_rce, qpBase);<br>>+ qpBase = cu->m_baseQp;<br>>+ int reEncode = m_top->m_rateControl->rowDiagonalVbvRateControl(m_pic, row, &m_rce, qpBase);<br>
> qpBase = Clip3((double)MIN_QP, (double)MAX_MAX_QP, qpBase);<br>>+ m_pic->m_rowDiagQp[row] = qpBase;<br>>+ m_pic->m_rowDiagQScale[row] = x265_qp2qScale(qpBase);<br>
>+ if (reEncode < 0)<br>>+ {<br>>+ m_bAllRowsStop = true;<br>>+ m_rows[row].m_completed = 0;<br>>+ m_rows[row].m_isReencode = true;<br>
>+ m_vbvResetTriggerRow = row;<br>>+ for (int bottomRows = m_numRows - 1; bottomRows >= row ; bottomRows--)<br>>+ {<br>>+ if (bottomRows!=row)<br>
>+ {<br>>+ //wait for each row to be idle <br>>+ while(m_rows[bottomRows].m_active && m_rows[bottomRows].m_busy)<br>>+ GIVE_UP_TIME();<br>
>+ }<br>>+ m_rows[bottomRows].m_isReencode = true;<br>>+ m_rows[bottomRows].m_completed = 0;<br>>+ m_pic->m_qpaAq[bottomRows] = 0;<br>
>+ m_pic->m_rowEncodedBits[bottomRows] = 0;<br>>+ m_pic->m_qpaRc[bottomRows] = 0;<br>>+ m_pic->m_numEncodedCusPerRow[bottomRows] = 0;<br>
>+ }<br>>+ }<br>> }<br>> }<br>> // Completed CU processing<br>>- m_rows[row].m_completed++;<br>>+ if (!m_rows[row].m_isReencode)<br>>+ m_rows[row].m_completed++;<br>
> if (m_rows[row].m_completed >= 2 && row < m_numRows - 1)<br>> {<br>> ScopedLock below(m_rows[row + 1].m_lock);<br>>@@ -1171,6 +1225,7 @@<br>> if (m_cfg->param->rc.vbvBufferSize > 0 && m_cfg->param->rc.vbvMaxBitrate > 0)<br>
> {<br>> m_pic->m_cuCostsForVbv[cuAddr] += m_pic->m_lowres.lowresCostForRc[idx];<br>>+ m_pic->m_intraCuCostsForVbv[cuAddr] += m_pic->m_lowres.intraCost[idx];<br>
> }<br>> cnt++;<br>> }<br></div></div></div></div><br>_______________________________________________<br>
x265-devel mailing list<br>
<a href="mailto:x265-devel@videolan.org">x265-devel@videolan.org</a><br>
<a href="https://mailman.videolan.org/listinfo/x265-devel" target="_blank">https://mailman.videolan.org/listinfo/x265-devel</a><br>
<br></blockquote></div><br></div></div>