disable hardware encoding if encoding fails too many times (#8327)

Signed-off-by: 21pages <sunboeasy@gmail.com>
This commit is contained in:
21pages
2024-06-12 23:37:51 +08:00
committed by GitHub
parent 610009528b
commit f559e9c74a
6 changed files with 45 additions and 11 deletions

View File

@@ -308,6 +308,8 @@ impl EncoderApi for AomEncoder {
fn is_hardware(&self) -> bool {
false
}
fn disable(&self) {}
}
impl AomEncoder {

View File

@@ -76,6 +76,8 @@ pub trait EncoderApi {
fn latency_free(&self) -> bool;
fn is_hardware(&self) -> bool;
fn disable(&self);
}
pub struct Encoder {
@@ -145,7 +147,6 @@ impl Encoder {
Err(e) => {
log::error!("new hw encoder failed: {e:?}, clear config");
HwCodecConfig::clear(false, true);
Self::update(EncodingUpdate::Check);
*ENCODE_CODEC_FORMAT.lock().unwrap() = CodecFormat::VP9;
Err(e)
}
@@ -158,7 +159,6 @@ impl Encoder {
Err(e) => {
log::error!("new vram encoder failed: {e:?}, clear config");
HwCodecConfig::clear(true, true);
Self::update(EncodingUpdate::Check);
*ENCODE_CODEC_FORMAT.lock().unwrap() = CodecFormat::VP9;
Err(e)
}

View File

@@ -15,7 +15,7 @@ use hbb_common::{
};
use hwcodec::{
common::{
get_gpu_signature, DataFormat,
DataFormat,
Quality::{self, *},
RateControl::{self, *},
},
@@ -210,6 +210,10 @@ impl EncoderApi for HwRamEncoder {
fn is_hardware(&self) -> bool {
true
}
fn disable(&self) {
HwCodecConfig::clear(false, true);
}
}
impl HwRamEncoder {
@@ -582,7 +586,7 @@ impl HwCodecConfig {
None => {
log::info!("try load cached hwcodec config");
let c = hbb_common::config::common_load::<HwCodecConfig>("_hwcodec");
let new_signature = get_gpu_signature();
let new_signature = hwcodec::common::get_gpu_signature();
if c.signature == new_signature {
log::debug!("load cached hwcodec config: {c:?}");
*CONFIG.lock().unwrap() = Some(c.clone());
@@ -647,6 +651,7 @@ impl HwCodecConfig {
}
}
}
crate::codec::Encoder::update(crate::codec::EncodingUpdate::Check);
}
}
@@ -679,7 +684,7 @@ pub fn check_available_hwcodec() -> String {
vram_encode: vram.0,
#[cfg(feature = "vram")]
vram_decode: vram.1,
signature: get_gpu_signature(),
signature: hwcodec::common::get_gpu_signature(),
};
log::debug!("{c:?}");
serde_json::to_string(&c).unwrap_or_default()

View File

@@ -246,6 +246,8 @@ impl EncoderApi for VpxEncoder {
fn is_hardware(&self) -> bool {
false
}
fn disable(&self) {}
}
impl VpxEncoder {

View File

@@ -194,6 +194,10 @@ impl EncoderApi for VRamEncoder {
fn is_hardware(&self) -> bool {
true
}
fn disable(&self) {
HwCodecConfig::clear(true, true);
}
}
impl VRamEncoder {