ec-hw: EncoderConfig::buffer_ms overrides the rate-control buffer (None keeps 20 ms below GOP 10, else 1000 ms)
Browse files at this commit600391da31602c1f32182660d4673e37980fa23bParent: 06c38da4 changed files +13 -5
- crates/ec-hw/src/enc/mod.rs +1 -1
- crates/ec-hw/src/hw.rs +1 -1
- crates/ec-hw/src/rate.rs +7 -3
- crates/ec-hw/src/types.rs +4 -0
crates/ec-hw/src/enc/mod.rsmodified+1 -1
| @@ -723,7 +723,7 @@ impl Encoder { | ||
| 723 | 723 | // quarter of a window of budget: radeonsi then spent 12.5% under the |
| 724 | 724 | // ask on a 2 s clip, and the gap is exactly that quarter over the |
| 725 | 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 | 727 | let hrd_bits = (u64::from(bits) * buffer_ms / 1000) as u32; |
| 728 | 728 | out.push(BufferType::EncMiscParameter(EncMiscParameter::HRD( |
| 729 | 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 | 934 | _ => ec_vk::RateControl::Cbr { |
| 935 | 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 | 3 | pub(crate) const RATE_WINDOW_MS: u32 = 1000; |
| 4 | 4 | |
| @@ -23,8 +23,12 @@ pub(crate) const RATE_WINDOW_MS: u32 = 1000; | ||
| 23 | 23 | /// So a GOP shorter than ten pictures gets a 20 ms buffer. A GOP of thirty keeps |
| 24 | 24 | /// the full rate window: the short buffer lands on the request there too, but |
| 25 | 25 | /// 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 | + } | |
| 28 | 32 | } |
| 29 | 33 | |
| 30 | 34 | /// 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 | 114 | /// Luma bit depth: 8, or 10 for H.265 and AV1. A 10-bit encoder takes its |
| 115 | 115 | /// pixels through [`Encoder::encode_16`] or [`HwEncoder::encode_16`]. |
| 116 | 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 | 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 | 152 | quality: 0, |
| 150 | 153 | colour: None, |
| 151 | 154 | bit_depth: 8, |
| 155 | + buffer_ms: None, | |
| 152 | 156 | } |
| 153 | 157 | } |
| 154 | 158 |