If there is hardware ram encoder as fallback, not require all adapters (#7987)

support the codec format

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages 2024-05-09 09:02:25 +08:00 committed by GitHub
parent 9d56e29a09
commit a31a68ba17
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 27 additions and 26 deletions

View File

@ -139,6 +139,7 @@ impl Encoder {
Err(e) => {
log::error!("new hw encoder failed: {e:?}, clear config");
hbb_common::config::HwCodecConfig::clear_ram();
Self::update(EncodingUpdate::Check);
*ENCODE_CODEC_FORMAT.lock().unwrap() = CodecFormat::VP9;
Err(e)
}
@ -151,6 +152,7 @@ impl Encoder {
Err(e) => {
log::error!("new vram encoder failed: {e:?}, clear config");
hbb_common::config::HwCodecConfig::clear_vram();
Self::update(EncodingUpdate::Check);
*ENCODE_CODEC_FORMAT.lock().unwrap() = CodecFormat::VP9;
Err(e)
}

View File

@ -96,10 +96,7 @@ impl EncoderApi for HwRamEncoder {
height: ctx.height as _,
bitrate,
}),
Err(_) => {
HwCodecConfig::clear_ram();
Err(anyhow!(format!("Failed to create encoder")))
}
Err(_) => Err(anyhow!(format!("Failed to create encoder"))),
}
}
_ => Err(anyhow!("encoder type mismatch")),

View File

@ -87,10 +87,7 @@ impl EncoderApi for VRamEncoder {
same_bad_len_counter: 0,
config,
}),
Err(_) => {
hbb_common::config::HwCodecConfig::clear_vram();
Err(anyhow!(format!("Failed to create encoder")))
}
Err(_) => Err(anyhow!(format!("Failed to create encoder"))),
}
}
_ => Err(anyhow!("encoder type mismatch")),
@ -213,32 +210,37 @@ impl VRamEncoder {
CodecFormat::H265 => DataFormat::H265,
_ => return vec![],
};
let Ok(displays) = crate::Display::all() else {
log::error!("failed to get displays");
return vec![];
};
if displays.is_empty() {
log::error!("no display found");
return vec![];
}
let luids = displays
.iter()
.map(|d| d.adapter_luid())
.collect::<Vec<_>>();
let v: Vec<_> = get_available_config()
.map(|c| c.e)
.unwrap_or_default()
.drain(..)
.filter(|c| c.data_format == data_format)
.collect();
if luids
.iter()
.all(|luid| v.iter().any(|f| Some(f.luid) == *luid))
{
if crate::hwcodec::HwRamEncoder::try_get(format).is_some() {
// has fallback, no need to require all adapters support
v
} else {
log::info!("not all adapters support {data_format:?}, luids = {luids:?}");
vec![]
let Ok(displays) = crate::Display::all() else {
log::error!("failed to get displays");
return vec![];
};
if displays.is_empty() {
log::error!("no display found");
return vec![];
}
let luids = displays
.iter()
.map(|d| d.adapter_luid())
.collect::<Vec<_>>();
if luids
.iter()
.all(|luid| v.iter().any(|f| Some(f.luid) == *luid))
{
v
} else {
log::info!("not all adapters support {data_format:?}, luids = {luids:?}");
vec![]
}
}
}