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 {
723 // quarter of a window of budget: radeonsi then spent 12.5% under the723 // quarter of a window of budget: radeonsi then spent 12.5% under the
724 // ask on a 2 s clip, and the gap is exactly that quarter over the724 // ask on a 2 s clip, and the gap is exactly that quarter over the
725 // clip length (measured, 2026-10-16). Its size: see `hrd_buffer_ms`.725 // 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));
727 let hrd_bits = (u64::from(bits) * buffer_ms / 1000) as u32;727 let hrd_bits = (u64::from(bits) * buffer_ms / 1000) as u32;
728 out.push(BufferType::EncMiscParameter(EncMiscParameter::HRD(728 out.push(BufferType::EncMiscParameter(EncMiscParameter::HRD(
729 EncMiscParameterHRD::new(hrd_bits, hrd_bits),729 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 {
933 },933 },
934 _ => ec_vk::RateControl::Cbr {934 _ => ec_vk::RateControl::Cbr {
935 bitrate,935 bitrate,
936- buffer_ms: hrd_buffer_ms(config.gop_size),936+ buffer_ms: hrd_buffer_ms(config),
937 },937 },
938 }938 }
939 }939 }
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};
2 2
3 pub(crate) const RATE_WINDOW_MS: u32 = 1000;3 pub(crate) const RATE_WINDOW_MS: u32 = 1000;
4 4
@@ -23,8 +23,12 @@ pub(crate) const RATE_WINDOW_MS: u32 = 1000;
23 /// So a GOP shorter than ten pictures gets a 20 ms buffer. A GOP of thirty keeps23 /// So a GOP shorter than ten pictures gets a 20 ms buffer. A GOP of thirty keeps
24 /// the full rate window: the short buffer lands on the request there too, but24 /// the full rate window: the short buffer lands on the request there too, but
25 /// costs 3.4 dB at the same rate.25 /// costs 3.4 dB at the same rate.
26-pub(crate) fn hrd_buffer_ms(gop_size: u32) -> u32 {26+pub(crate) fn hrd_buffer_ms(config: &EncoderConfig) -> u32 {
27- if gop_size < 10 { 20 } else { RATE_WINDOW_MS }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+ }
28 }32 }
29 33
30 /// Closed-loop correction of the driver's rate control, which lands off the ask34 /// 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 {
114 /// Luma bit depth: 8, or 10 for H.265 and AV1. A 10-bit encoder takes its114 /// Luma bit depth: 8, or 10 for H.265 and AV1. A 10-bit encoder takes its
115 /// pixels through [`Encoder::encode_16`] or [`HwEncoder::encode_16`].115 /// pixels through [`Encoder::encode_16`] or [`HwEncoder::encode_16`].
116 pub bit_depth: u8,116 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>,
117 }120 }
118 121
119 /// H.265 E.2.1 / H.264 E.1.1 colour description code points for the VUI.122 /// H.265 E.2.1 / H.264 E.1.1 colour description code points for the VUI.
@@ -149,6 +152,7 @@ impl EncoderConfig {
149 quality: 0,152 quality: 0,
150 colour: None,153 colour: None,
151 bit_depth: 8,154 bit_depth: 8,
155+ buffer_ms: None,
152 }156 }
153 }157 }
154 158