forge
Explore
Log in

Don't you dare go Hollow

ec-hw: EncoderConfig::buffer_ms overrides the rate-control buffer (None keeps 20 ms below GOP 10, else 1000 ms)

Browse files at this commit

600391da31602c1f32182660d4673e37980fa23bAhmet Kaan GümüşParent: 06c38da
crates/ec-hw/src/enc/mod.rsmodified+1 -1
@@ -723,7 +723,7 @@ impl Encoder {
723723 // quarter of a window of budget: radeonsi then spent 12.5% under the
724724 // ask on a 2 s clip, and the gap is exactly that quarter over the
725725 // clip length (measured, 2026-10-16). Its size: see `hrd_buffer_ms`.
726- let buffer_ms = u64::from(hrd_buffer_ms(self.config.gop_size));
726+ let buffer_ms = u64::from(hrd_buffer_ms(&self.config));
727727 let hrd_bits = (u64::from(bits) * buffer_ms / 1000) as u32;
728728 out.push(BufferType::EncMiscParameter(EncMiscParameter::HRD(
729729 EncMiscParameterHRD::new(hrd_bits, hrd_bits),
crates/ec-hw/src/hw.rsmodified+1 -1
@@ -933,7 +933,7 @@ fn vk_rate(config: &EncoderConfig, bitrate: u32) -> ec_vk::RateControl {
933933 },
934934 _ => ec_vk::RateControl::Cbr {
935935 bitrate,
936- buffer_ms: hrd_buffer_ms(config.gop_size),
936+ buffer_ms: hrd_buffer_ms(config),
937937 },
938938 }
939939 }
crates/ec-hw/src/rate.rsmodified+7 -3
@@ -1,4 +1,4 @@
1-use crate::types::{RateControlMode, Tunings};
1+use crate::types::{EncoderConfig, RateControlMode, Tunings};
22
33 pub(crate) const RATE_WINDOW_MS: u32 = 1000;
44
@@ -23,8 +23,12 @@ pub(crate) const RATE_WINDOW_MS: u32 = 1000;
2323 /// So a GOP shorter than ten pictures gets a 20 ms buffer. A GOP of thirty keeps
2424 /// the full rate window: the short buffer lands on the request there too, but
2525 /// costs 3.4 dB at the same rate.
26-pub(crate) fn hrd_buffer_ms(gop_size: u32) -> u32 {
27- if gop_size < 10 { 20 } else { RATE_WINDOW_MS }
26+pub(crate) fn hrd_buffer_ms(config: &EncoderConfig) -> u32 {
27+ match config.buffer_ms {
28+ Some(ms) => ms.max(1),
29+ None if config.gop_size < 10 => 20,
30+ None => RATE_WINDOW_MS,
31+ }
2832 }
2933
3034 /// Closed-loop correction of the driver's rate control, which lands off the ask
crates/ec-hw/src/types.rsmodified+4 -0
@@ -114,6 +114,9 @@ pub struct EncoderConfig {
114114 /// Luma bit depth: 8, or 10 for H.265 and AV1. A 10-bit encoder takes its
115115 /// pixels through [`Encoder::encode_16`] or [`HwEncoder::encode_16`].
116116 pub bit_depth: u8,
117+ /// Rate-control (HRD/VBV) buffer in milliseconds of the bitrate, or `None`
118+ /// for 20 ms below a GOP of ten pictures and 1000 ms otherwise.
119+ pub buffer_ms: Option<u32>,
117120 }
118121
119122 /// H.265 E.2.1 / H.264 E.1.1 colour description code points for the VUI.
@@ -149,6 +152,7 @@ impl EncoderConfig {
149152 quality: 0,
150153 colour: None,
151154 bit_depth: 8,
155+ buffer_ms: None,
152156 }
153157 }
154158