perf(android): low-latency decode overhaul — vendor keys, async loop, system tuning
Close the latency gap on the Android client with per-SoC decoder tuning, an event-driven decode loop, and full system integration. - Decoder selection: rank MediaCodecList decoders in Kotlin (hardware/vendor preferred, software avoided, FEATURE_LowLatency probed) and create the chosen one by name. Per-SoC low-latency keys gated on the codec-name prefix: Qualcomm picture-order + low-latency, Exynos (also Google Tensor), Amlogic, HiSilicon; MediaTek vdec-lowlatency set unconditionally. operating-rate = MAX (Qualcomm) vs priority = 0 (else) are mutually exclusive. NVIDIA/Rockchip/Realtek have no vendor key — covered by ranking + the standard low-latency key. - Async decode loop: AMediaCodec async-notify replaces the poll loop, presenting a decoded frame the instant it is ready instead of waiting out a poll interval. Behind USE_ASYNC_DECODE with the synchronous loop kept for A/B during bring-up. - System integration: Wi-Fi FULL_LOW_LATENCY lock and HDMI ALLM (setPreferMinimalPostProcessing) for the stream's lifetime; game_mode_config.xml opting out of OEM downscaling / FPS overrides. - Pipeline: boost the data-plane pump + audio thread priorities, AAudio usage=Game, DSCP marking on by default on Android, ADPF setPreferPowerEfficiency(false), and setFrameRateWithChangeStrategy(ALWAYS) to force the HDMI mode switch on TV. - lowLatencyMode master toggle (default on) as the escape hatch; the stats HUD now shows the resolved decoder name. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -22,9 +22,21 @@ pub struct VideoStats {
|
||||
/// they (and the caller's latency computation — see `enabled`) early-out on this flag alone.
|
||||
/// Off until Kotlin shows the HUD.
|
||||
enabled: AtomicBool,
|
||||
/// The resolved decoder identity for the HUD: the codec's actual `AMediaCodec` name (e.g.
|
||||
/// `c2.qti.avc.decoder`) and whether it advertised `FEATURE_LowLatency`. Set once when the
|
||||
/// decode thread creates the codec (`set_decoder`), read one-shot by `nativeVideoDecoderLabel`.
|
||||
/// Separate from `inner` (never touched per-frame) so naming it costs nothing on the hot path.
|
||||
decoder: Mutex<Option<DecoderInfo>>,
|
||||
inner: Mutex<Inner>,
|
||||
}
|
||||
|
||||
/// The chosen decoder's identity, surfaced on the stats HUD so before/after latency comparisons
|
||||
/// name the codec that produced them.
|
||||
struct DecoderInfo {
|
||||
name: String,
|
||||
low_latency: bool,
|
||||
}
|
||||
|
||||
struct Inner {
|
||||
window_start: Instant,
|
||||
frames: u64,
|
||||
@@ -79,6 +91,7 @@ impl VideoStats {
|
||||
pub fn new() -> VideoStats {
|
||||
VideoStats {
|
||||
enabled: AtomicBool::new(false),
|
||||
decoder: Mutex::new(None),
|
||||
inner: Mutex::new(Inner {
|
||||
window_start: Instant::now(),
|
||||
frames: 0,
|
||||
@@ -121,6 +134,36 @@ impl VideoStats {
|
||||
}
|
||||
}
|
||||
|
||||
/// Record the resolved decoder identity for the HUD — the codec's real `AMediaCodec` name and
|
||||
/// whether it reported `FEATURE_LowLatency`. Called once from the decode thread right after the
|
||||
/// codec is created (before `configure`), overwriting any prior value on a surface recreate.
|
||||
// Set only by the android-only decode thread; unreferenced on the host build — expected.
|
||||
#[cfg_attr(not(target_os = "android"), allow(dead_code))]
|
||||
pub fn set_decoder(&self, name: &str, low_latency: bool) {
|
||||
let mut g = self
|
||||
.decoder
|
||||
.lock()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
*g = Some(DecoderInfo {
|
||||
name: name.to_owned(),
|
||||
low_latency,
|
||||
});
|
||||
}
|
||||
|
||||
/// The decoder label for the HUD, e.g. `c2.qti.avc.decoder · low-latency`, or `""` before the
|
||||
/// decode thread has resolved one. Cheap (a lock + a string build); safe on the UI thread.
|
||||
pub fn decoder_label(&self) -> String {
|
||||
let g = self
|
||||
.decoder
|
||||
.lock()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
match &*g {
|
||||
Some(d) if d.low_latency => format!("{} · low-latency", d.name),
|
||||
Some(d) => d.name.clone(),
|
||||
None => String::new(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Record one received access unit: its wire size and (if in range) its capture→received
|
||||
/// `host+network` stage sample. Receipt is the fps/goodput counting point per the spec.
|
||||
// Driven only by the android-only decode thread; unreferenced on the host build — expected.
|
||||
|
||||
Reference in New Issue
Block a user