Rate control (5): fluid flow model

Rate control (5): fluid flow model

The main function of rate control is to adapt to bandwidth requirements to compress the rate and prevent frequent network packet loss

The fluid flow model is to simulate the state of bit data in the network and buffer, which is explained below from the perspective of the decoder.

The CPB (coded picture buffer) in the HRD (hypothetical reference decoder) is used to buffer bit data. The capacity of the CPB is limited. If the CPB is full, the following data will overflow and cause data loss ( overflow ). Space creates waste ( underflow ).

The state of CPB can be described by three quantities, R, B, and F. R represents network transmission bandwidth, B represents CPB capacity, and F represents CPB fullness. The following figure is a state change diagram of CPB:

 

Where i represents the i-th frame image, bi represents the bit number of the i-th frame image, and f represents the frame rate.

What are overflow and underflow?

An important function of the rate control algorithm is to prevent CPB from overflowing and underflowing.

 

The above two formulas describe the occurrence of overflow and underflow respectively.

The formula (1) indicates that at a certain moment, the i-th frame data is taken out of the CPB for decoding, and the network writes R/f bit data into the CPB. At this time, the number of bits of the CPB exceeds the capacity B and overflow occurs. The figure below shows an overflow situation.

 

The formula (2) indicates that the i-th frame data is taken out from the CPB for decoding at a certain moment, but the data in the CPB is not enough, and an underflow occurs. The figure below shows an underflow situation.

 

Prevent overflow and underflow

In order to prevent the occurrence of overflow and underflow, frame-level bit rate adjustment is implemented in HM to keep the fullness of CPB at 10%-90%. The bit rate adjustment is done before calculating the image lambda and QP.

As shown below:

 

The above state diagram can be expressed by the following formula:

 

tbi is the target bit of the i-th frame calculated by the rate control algorithm in HM. If an overflow occurs, set tbi to Fi+R/f-Bx0.9; if an overflow occurs, set tbi to max(200,Fi -Bx0.1).

Reference Code

#if U0132_TARGET_BITS_SATURATION
      if (m_pcRateCtrl->getCpbSaturationEnabled() && frameLevel != 0)
      {
        Int estimatedCpbFullness = m_pcRateCtrl->getCpbState() + m_pcRateCtrl->getBufferingRate();
​
        // prevent overflow
        if (estimatedCpbFullness - estimatedBits > (Int)(m_pcRateCtrl->getCpbSize()*0.9f))
        {
          estimatedBits = estimatedCpbFullness - (Int)(m_pcRateCtrl->getCpbSize()*0.9f);
        }
​
        estimatedCpbFullness -= m_pcRateCtrl->getBufferingRate();
        // prevent underflow
#if V0078_ADAPTIVE_LOWER_BOUND
        if (estimatedCpbFullness - estimatedBits < m_pcRateCtrl->getRCPic()->getLowerBound())
        {
          estimatedBits = max(200, estimatedCpbFullness - m_pcRateCtrl->getRCPic()->getLowerBound());
        }
#else
        if (estimatedCpbFullness - estimatedBits < (Int)(m_pcRateCtrl->getCpbSize()*0.1f))
        {
          estimatedBits = max(200, estimatedCpbFullness - (Int)(m_pcRateCtrl->getCpbSize()*0.1f));
        }
#endif
​
        m_pcRateCtrl->getRCPic()->setTargetBits(estimatedBits);
      }
#endif

reference

JCTVC-U0132

If you are interested, please follow the WeChat public account Video Coding

 

Guess you like

Origin blog.csdn.net/Dillon2015/article/details/106498257