mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-03-17 02:01:01 +03:00
add ffmpeg mediacodec h264/h265 encode (#8028)
* Check available when app start from kotlin via get codec info * For latency free, repeat encode 10 frame at most when capture return WouldBlock * For changing quality, kotlin support but jni doesn't support, rerun video service when quality is manualy changed * 3 or 6 times bitrate for mediacodec because its quality is poor Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
@@ -70,6 +70,10 @@ pub trait EncoderApi {
|
||||
fn bitrate(&self) -> u32;
|
||||
|
||||
fn support_abr(&self) -> bool;
|
||||
|
||||
fn support_changing_quality(&self) -> bool;
|
||||
|
||||
fn latency_free(&self) -> bool;
|
||||
}
|
||||
|
||||
pub struct Encoder {
|
||||
@@ -138,6 +142,9 @@ impl Encoder {
|
||||
}),
|
||||
Err(e) => {
|
||||
log::error!("new hw encoder failed: {e:?}, clear config");
|
||||
#[cfg(target_os = "android")]
|
||||
crate::android::ffi::clear_codec_info();
|
||||
#[cfg(not(target_os = "android"))]
|
||||
hbb_common::config::HwCodecConfig::clear_ram();
|
||||
Self::update(EncodingUpdate::Check);
|
||||
*ENCODE_CODEC_FORMAT.lock().unwrap() = CodecFormat::VP9;
|
||||
@@ -346,7 +353,14 @@ impl Encoder {
|
||||
EncoderCfg::AOM(_) => CodecFormat::AV1,
|
||||
#[cfg(feature = "hwcodec")]
|
||||
EncoderCfg::HWRAM(hw) => {
|
||||
if hw.name.to_lowercase().contains("h264") {
|
||||
let name = hw.name.to_lowercase();
|
||||
if name.contains("vp8") {
|
||||
CodecFormat::VP8
|
||||
} else if name.contains("vp9") {
|
||||
CodecFormat::VP9
|
||||
} else if name.contains("av1") {
|
||||
CodecFormat::AV1
|
||||
} else if name.contains("h264") {
|
||||
CodecFormat::H264
|
||||
} else {
|
||||
CodecFormat::H265
|
||||
@@ -817,7 +831,7 @@ impl Decoder {
|
||||
|
||||
#[cfg(any(feature = "hwcodec", feature = "mediacodec"))]
|
||||
pub fn enable_hwcodec_option() -> bool {
|
||||
if cfg!(windows) || cfg!(target_os = "linux") || cfg!(feature = "mediacodec") {
|
||||
if cfg!(windows) || cfg!(target_os = "linux") || cfg!(target_os = "android") {
|
||||
if let Some(v) = Config2::get().options.get("enable-hwcodec") {
|
||||
return v != "N";
|
||||
}
|
||||
@@ -847,6 +861,15 @@ impl Default for Quality {
|
||||
}
|
||||
}
|
||||
|
||||
impl Quality {
|
||||
pub fn is_custom(&self) -> bool {
|
||||
match self {
|
||||
Quality::Custom(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn base_bitrate(width: u32, height: u32) -> u32 {
|
||||
#[allow(unused_mut)]
|
||||
let mut base_bitrate = ((width * height) / 1000) as u32; // same as 1.1.9
|
||||
|
||||
Reference in New Issue
Block a user