[x265] [PATCH] rc: release RC lock after RateControlStart for CQP and CRF(without VBV)

Steve Borho steve at borho.org
Tue Mar 17 15:00:15 CET 2015


On 03/17, aarthi at multicorewareinc.com wrote:
> # HG changeset patch
> # User Aarthi Thirumalai
> # Date 1426573364 -19800
> #      Tue Mar 17 11:52:44 2015 +0530
> # Node ID 447345368ddf982deb3cda4fdff36860e1364189
> # Parent  b9948752d5516a72eeaf824e3ee6f0feb097381c
> rc: release RC lock after RateControlStart for CQP and CRF(without VBV)
> 
> RateControlUpdateStats is not needed for CQP and CRF - without vbv,
> prevent floating point divide by zero issue in CQP

queued for testing

> diff -r b9948752d551 -r 447345368ddf source/encoder/frameencoder.cpp
> --- a/source/encoder/frameencoder.cpp	Mon Mar 16 20:40:12 2015 -0500
> +++ b/source/encoder/frameencoder.cpp	Tue Mar 17 11:52:44 2015 +0530
> @@ -1042,24 +1042,24 @@
>       * after refLagRows (the number of rows reference frames must have completed
>       * before referencees may begin encoding) */
>      uint32_t rowCount = 0;
> -    if (m_param->rc.rateControlMode == X265_RC_ABR)
> +    if (m_param->rc.rateControlMode == X265_RC_ABR || bIsVbv)
>      {
>          if ((uint32_t)m_rce.encodeOrder <= 2 * (m_param->fpsNum / m_param->fpsDenom))
>              rowCount = X265_MIN((m_numRows + 1) / 2, m_numRows - 1);
>          else
>              rowCount = X265_MIN(m_refLagRows, m_numRows - 1);
> -    }
> -    if (row == rowCount)
> -    {
> -        m_rce.rowTotalBits = 0;
> -        if (bIsVbv)
> -            for (uint32_t i = 0; i < rowCount; i++)
> -                m_rce.rowTotalBits += curEncData.m_rowStat[i].encodedBits;
> -        else
> -            for (uint32_t cuAddr = 0; cuAddr < rowCount * numCols; cuAddr++)
> -                m_rce.rowTotalBits += curEncData.m_cuStat[cuAddr].totalBits;
> +        if (row == rowCount)
> +        {
> +            m_rce.rowTotalBits = 0;
> +            if (bIsVbv)
> +                for (uint32_t i = 0; i < rowCount; i++)
> +                    m_rce.rowTotalBits += curEncData.m_rowStat[i].encodedBits;
> +            else
> +                for (uint32_t cuAddr = 0; cuAddr < rowCount * numCols; cuAddr++)
> +                    m_rce.rowTotalBits += curEncData.m_cuStat[cuAddr].totalBits;
>  
> -        m_top->m_rateControl->rateControlUpdateStats(&m_rce);
> +            m_top->m_rateControl->rateControlUpdateStats(&m_rce);
> +        }
>      }
>  
>      /* flush row bitstream (if WPP and no SAO) or flush frame if no WPP and no SAO */
> diff -r b9948752d551 -r 447345368ddf source/encoder/ratecontrol.cpp
> --- a/source/encoder/ratecontrol.cpp	Mon Mar 16 20:40:12 2015 -0500
> +++ b/source/encoder/ratecontrol.cpp	Tue Mar 17 11:52:44 2015 +0530
> @@ -1077,9 +1077,20 @@
>              rce->frameSizePlanned = predictSize(&m_pred[m_sliceType], m_qp, (double)m_currentSatd);
>          }
>      }
> -    // Do not increment m_startEndOrder here. Make rateControlEnd of previous thread
> -    // to wait until rateControlUpdateStats of this frame is called
>      m_framesDone++;
> +
> +    /* CQP and CRF (without capped VBV) doesn't use mid-frame statistics to 
> +     * tune RateControl parameters for other frames.
> +     * Hence, for these modes, update m_startEndOrder and unlock RC for previous threads waiting in
> +     * RateControlEnd here.those modes here. For the rest - ABR
> +     * and VBV, unlock only after rateControlUpdateStats of this frame is called */
> +    if (m_param->rc.rateControlMode != X265_RC_ABR && !m_isVbv)
> +    {
> +        m_startEndOrder.incr();
> +
> +        if (rce->encodeOrder < m_param->frameNumThreads - 1)
> +            m_startEndOrder.incr(); // faked rateControlEnd calls for negative frames
> +    }
>      return m_qp;
>  }
>  
> @@ -1588,10 +1599,13 @@
>  
>      /* do not allow the next frame to enter rateControlStart() until this
>       * frame has updated its mid-frame statistics */
> -    m_startEndOrder.incr();
> +    if (m_param->rc.rateControlMode == X265_RC_ABR || m_isVbv)
> +    {
> +        m_startEndOrder.incr();
>  
> -    if (rce->encodeOrder < m_param->frameNumThreads - 1)
> -        m_startEndOrder.incr(); // faked rateControlEnd calls for negative frames
> +        if (rce->encodeOrder < m_param->frameNumThreads - 1)
> +            m_startEndOrder.incr(); // faked rateControlEnd calls for negative frames
> +    }
>  }
>  
>  void RateControl::checkAndResetABR(RateControlEntry* rce, bool isFrameDone)
> _______________________________________________
> x265-devel mailing list
> x265-devel at videolan.org
> https://mailman.videolan.org/listinfo/x265-devel

-- 
Steve Borho


More information about the x265-devel mailing list