vram avoid always fallback to gdi (#8272)

Signed-off-by: 21pages <sunboeasy@gmail.com>
This commit is contained in:
21pages 2024-06-06 22:52:31 +08:00 committed by GitHub
parent 9562768a04
commit 9d42ee9df8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 1 deletions

View File

@ -1,5 +1,5 @@
use std::{
collections::HashMap,
collections::{HashMap, HashSet},
ffi::c_void,
sync::{Arc, Mutex},
};
@ -30,6 +30,7 @@ use hwcodec::{
// https://learn.microsoft.com/en-us/windows/win32/api/d3d12/nf-d3d12-id3d12device-getadapterluid#remarks
lazy_static::lazy_static! {
static ref ENOCDE_NOT_USE: Arc<Mutex<HashMap<usize, bool>>> = Default::default();
static ref FALLBACK_GDI_DISPLAYS: Arc<Mutex<HashSet<usize>>> = Default::default();
}
#[derive(Debug, Clone)]
@ -212,6 +213,11 @@ impl VRamEncoder {
}
pub fn available(format: CodecFormat) -> Vec<FeatureContext> {
let fallbacks = FALLBACK_GDI_DISPLAYS.lock().unwrap().clone();
if !fallbacks.is_empty() {
log::info!("fallback gdi displays not empty: {fallbacks:?}");
return vec![];
}
let not_use = ENOCDE_NOT_USE.lock().unwrap().clone();
if not_use.values().any(|not_use| *not_use) {
log::info!("currently not use vram encoders: {not_use:?}");
@ -298,6 +304,14 @@ impl VRamEncoder {
log::info!("set display#{display} not use vram encode to {not_use}");
ENOCDE_NOT_USE.lock().unwrap().insert(display, not_use);
}
pub fn set_fallback_gdi(display: usize, fallback: bool) {
if fallback {
FALLBACK_GDI_DISPLAYS.lock().unwrap().insert(display);
} else {
FALLBACK_GDI_DISPLAYS.lock().unwrap().remove(&display);
}
}
}
pub struct VRamDecoder {

View File

@ -528,6 +528,7 @@ fn run(vs: VideoService) -> ResultType<()> {
#[cfg(all(windows, feature = "vram"))]
if c.is_gdi() && encoder.input_texture() {
log::info!("changed to gdi when using vram");
VRamEncoder::set_fallback_gdi(display_idx, true);
bail!("SWITCH");
}
check_privacy_mode_changed(&sp, c.privacy_mode_id)?;
@ -568,6 +569,10 @@ fn run(vs: VideoService) -> ResultType<()> {
}
#[cfg(windows)]
{
#[cfg(feature = "vram")]
if try_gdi == 1 && !c.is_gdi() {
VRamEncoder::set_fallback_gdi(display_idx, false);
}
try_gdi = 0;
}
Ok(())