[x265] [PATCH] vbv: enable row resets during vbv when mid-frame qp adjustemets are too high/low
chen
chenm003 at 163.com
Mon Mar 10 22:21:35 CET 2014
>+ //block current row if previous row is getting reencoded or prev row reference cus are not completed.
>+ ScopedLock self(curRow.m_lock);
>+ 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))
>+ {
>+ m_rows[row].m_active = false;
>+ m_rows[row].m_busy = false;
>+ m_totalTime = m_totalTime + (x265_mdate() - startTime);
>+ return;
>+ }
Seems you use bottomRows to deactive row thread, but most thread will continue to work.
May we reset col to 0 for all rows below re-encode row.
> for (uint32_t col = curRow.m_completed; col < numCols; col++)
> {
>+ //reset current row data if reencoded is turned on this row
>+ if (m_rows[row].m_isReencode == true )
>+ {
>+ col = 0;
>+ m_bAllRowsStop = false;
>+ m_rows[row].m_isReencode = false;
>+ }
> const uint32_t cuAddr = lineStartCUAddr + col;
> TComDataCU* cu = m_pic->getCU(cuAddr);
> cu->initCU(m_pic, cuAddr);
>@@ -1069,16 +1089,26 @@
> codeRow.m_entropyCoder.resetEntropy();
> TEncSbac *bufSbac = (m_cfg->param->bEnableWavefront && col == 0 && row > 0) ? &m_rows[row - 1].m_bufferSbacCoder : NULL;
>
>- if ((uint32_t)row >= col && (row != 0) && isVbv)
>- qpBase = m_pic->getCU(cuAddr - numCols + 1)->m_baseQp;
>+ if(isVbv)
>+ {
>+ if ((uint32_t)row == 0)
>+ m_pic->m_rowDiagQp[row] = m_pic->m_avgQpRc;
>+
>+ if ((uint32_t)row >= col && (row != 0) && m_vbvResetTriggerRow != row)
>+ cu->m_baseQp = m_pic->getCU(cuAddr - numCols + 1)->m_baseQp;
>+ else
>+ cu->m_baseQp = m_pic->m_rowDiagQp[row];
>+ }
>+ else
>+ cu->m_baseQp = m_pic->m_avgQpRc;
>
> if (m_cfg->param->rc.aqMode || isVbv)
> {
>- int qp = calcQpForCu(m_pic, cuAddr, qpBase);
>+ int qp = calcQpForCu(m_pic, cuAddr, cu->m_baseQp);
> setLambda(qp, row);
> qp = X265_MIN(qp, MAX_QP);
> cu->setQP(0, char(qp));
>- cu->m_baseQp = qpBase;
>+
> if (m_cfg->param->rc.aqMode)
> m_pic->m_qpaAq[row] += qp;
> }
>@@ -1087,22 +1117,46 @@
> {
> // Update encoded bits, satdCost, baseQP for each CU
> m_pic->m_rowDiagSatd[row] += m_pic->m_cuCostsForVbv[cuAddr];
>+ m_pic->m_rowDiagIntraSatd[row] += m_pic->m_intraCuCostsForVbv[cuAddr];
> m_pic->m_rowEncodedBits[row] += cu->m_totalBits;
> m_pic->m_numEncodedCusPerRow[row] = cuAddr;
> m_pic->m_qpaRc[row] += cu->m_baseQp;
>
>- if ((uint32_t)row == col)
>- m_pic->m_rowDiagQp[row] = qpBase;
>-
> // If current block is at row diagonal checkpoint, call vbv ratecontrol.
> if ((uint32_t)row == col && row != 0)
> {
>- m_top->m_rateControl->rowDiagonalVbvRateControl(m_pic, row, &m_rce, qpBase);
>+ qpBase = cu->m_baseQp;
>+ int reEncode = m_top->m_rateControl->rowDiagonalVbvRateControl(m_pic, row, &m_rce, qpBase);
> qpBase = Clip3((double)MIN_QP, (double)MAX_MAX_QP, qpBase);
>+ m_pic->m_rowDiagQp[row] = qpBase;
>+ m_pic->m_rowDiagQScale[row] = x265_qp2qScale(qpBase);
>+ if (reEncode < 0)
>+ {
>+ m_bAllRowsStop = true;
>+ m_rows[row].m_completed = 0;
>+ m_rows[row].m_isReencode = true;
>+ m_vbvResetTriggerRow = row;
>+ for (int bottomRows = m_numRows - 1; bottomRows >= row ; bottomRows--)
>+ {
>+ if (bottomRows!=row)
>+ {
>+ //wait for each row to be idle
>+ while(m_rows[bottomRows].m_active && m_rows[bottomRows].m_busy)
>+ GIVE_UP_TIME();
>+ }
>+ m_rows[bottomRows].m_isReencode = true;
>+ m_rows[bottomRows].m_completed = 0;
>+ m_pic->m_qpaAq[bottomRows] = 0;
>+ m_pic->m_rowEncodedBits[bottomRows] = 0;
>+ m_pic->m_qpaRc[bottomRows] = 0;
>+ m_pic->m_numEncodedCusPerRow[bottomRows] = 0;
>+ }
>+ }
> }
> }
> // Completed CU processing
>- m_rows[row].m_completed++;
>+ if (!m_rows[row].m_isReencode)
>+ m_rows[row].m_completed++;
> if (m_rows[row].m_completed >= 2 && row < m_numRows - 1)
> {
> ScopedLock below(m_rows[row + 1].m_lock);
>@@ -1171,6 +1225,7 @@
> if (m_cfg->param->rc.vbvBufferSize > 0 && m_cfg->param->rc.vbvMaxBitrate > 0)
> {
> m_pic->m_cuCostsForVbv[cuAddr] += m_pic->m_lowres.lowresCostForRc[idx];
>+ m_pic->m_intraCuCostsForVbv[cuAddr] += m_pic->m_lowres.intraCost[idx];
> }
> cnt++;
> }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20140311/cda017cb/attachment.html>
More information about the x265-devel
mailing list