update method
Update the controller after encoding a frame.
frameBytes is the size of the produced bitstream (in bytes).
Implementation
void update({required int frameBytes, required bool isKey}) {
final actualBits = frameBytes * 8;
final target =
isKey ? targetBitsPerFrame * keyframeBoost : targetBitsPerFrame;
_bufferBits += actualBits - target;
// Clamp buffer to ±2 windows to keep response bounded if content
// jumps far from the operating point.
final windowBits = targetBitrateBps * bufferWindowSeconds;
final clamp = 2.0 * windowBits;
if (_bufferBits > clamp) _bufferBits = clamp;
if (_bufferBits < -clamp) _bufferBits = -clamp;
_framesEncoded += 1;
_totalBitsEmitted += actualBits;
_consecutiveDrops = 0;
}