mirror of
https://github.com/weyne85/rustdesk.git
synced 2025-10-29 17:00:05 +00:00
Not require both max-width and max-height of mediacodec larger than (#8036)
screen width and screen height * Only use hardware codec, when api < 29, judge with codec name prefix. Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
@@ -178,6 +178,8 @@ pub struct MediaCodecInfo {
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
pub struct MediaCodecInfos {
|
||||
pub version: usize,
|
||||
pub w: usize,
|
||||
pub h: usize,
|
||||
pub codecs: Vec<MediaCodecInfo>,
|
||||
}
|
||||
|
||||
|
||||
@@ -416,6 +416,7 @@ fn get_config() -> ResultType<Available> {
|
||||
#[cfg(target_os = "android")]
|
||||
{
|
||||
let info = crate::android::ffi::get_codec_info();
|
||||
log::info!("all codec info: {info:?}");
|
||||
struct T {
|
||||
name_prefix: &'static str,
|
||||
data_format: DataFormat,
|
||||
@@ -440,16 +441,26 @@ fn get_config() -> ResultType<Available> {
|
||||
c.is_encoder
|
||||
&& c.mime_type.as_str() == get_mime_type(t.data_format)
|
||||
&& c.nv12
|
||||
&& c.hw == Some(true) //only use hardware codec
|
||||
})
|
||||
.collect();
|
||||
log::debug!("available {:?} encoders: {codecs:?}", t.data_format);
|
||||
let screen_wh = std::cmp::max(info.w, info.h);
|
||||
let mut best = None;
|
||||
if let Some(c) = codecs.iter().find(|c| c.hw == Some(true)) {
|
||||
best = Some(c.name.clone());
|
||||
} else if let Some(c) = codecs.iter().find(|c| c.hw == None) {
|
||||
best = Some(c.name.clone());
|
||||
} else if let Some(c) = codecs.first() {
|
||||
best = Some(c.name.clone());
|
||||
if let Some(codec) = codecs
|
||||
.iter()
|
||||
.find(|c| c.max_width >= screen_wh && c.max_height >= screen_wh)
|
||||
{
|
||||
best = Some(codec.name.clone());
|
||||
} else {
|
||||
// find the max resolution
|
||||
let mut max_area = 0;
|
||||
for codec in codecs.iter() {
|
||||
if codec.max_width * codec.max_height > max_area {
|
||||
best = Some(codec.name.clone());
|
||||
max_area = codec.max_width * codec.max_height;
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(best) = best {
|
||||
e.push(CodecInfo {
|
||||
|
||||
Reference in New Issue
Block a user