videotoolbox ram codec (#8683)

* h265 encoding: the second frame always fails, use repeat encoding to achieve real-time encoding
* h264 encoding: Not supported because encoding fails too frequently, about 50%, with one failure followed by another success.
* h264/h265 decoding: No issues found.
* Does not support dynamically changing the bitrate and changing the quality by resetting the encoder.

Signed-off-by: 21pages <sunboeasy@gmail.com>
This commit is contained in:
21pages
2024-07-12 11:08:51 +08:00
committed by GitHub
Unverified
parent 0ea88ce6ff
commit 821f7245b0
6 changed files with 22 additions and 21 deletions

View File

@@ -838,7 +838,7 @@ impl Decoder {
pub fn enable_hwcodec_option() -> bool {
use hbb_common::config::keys::OPTION_ENABLE_HWCODEC;
if cfg!(windows) || cfg!(target_os = "linux") || cfg!(target_os = "android") {
if !cfg!(target_os = "ios") {
return option2bool(
OPTION_ENABLE_HWCODEC,
&Config::get_option(OPTION_ENABLE_HWCODEC),

View File

@@ -192,19 +192,21 @@ impl EncoderApi for HwRamEncoder {
}
fn support_abr(&self) -> bool {
["qsv", "vaapi", "mediacodec"]
["qsv", "vaapi", "mediacodec", "videotoolbox"]
.iter()
.all(|&x| !self.config.name.contains(x))
}
fn support_changing_quality(&self) -> bool {
["vaapi", "mediacodec"]
["vaapi", "mediacodec", "videotoolbox"]
.iter()
.all(|&x| !self.config.name.contains(x))
}
fn latency_free(&self) -> bool {
!self.config.name.contains("mediacodec")
["mediacodec", "videotoolbox"]
.iter()
.all(|&x| !self.config.name.contains(x))
}
fn is_hardware(&self) -> bool {
@@ -501,12 +503,12 @@ pub struct HwCodecConfig {
// portable: ui start check process, check process send to ui
// sciter and unilink: get from ipc server
impl HwCodecConfig {
#[cfg(any(target_os = "windows", target_os = "linux"))]
#[cfg(not(any(target_os = "android", target_os = "ios")))]
pub fn set(config: String) {
let config = serde_json::from_str(&config).unwrap_or_default();
log::info!("set hwcodec config");
log::debug!("{config:?}");
#[cfg(windows)]
#[cfg(any(windows, target_os = "macos"))]
hbb_common::config::common_store(&config, "_hwcodec");
*CONFIG.lock().unwrap() = Some(config);
*CONFIG_SET_BY_IPC.lock().unwrap() = true;
@@ -578,7 +580,7 @@ impl HwCodecConfig {
..Default::default()
}
}
#[cfg(windows)]
#[cfg(any(windows, target_os = "macos"))]
{
let config = CONFIG.lock().unwrap().clone();
match config {
@@ -606,13 +608,13 @@ impl HwCodecConfig {
{
CONFIG.lock().unwrap().clone().unwrap_or_default()
}
#[cfg(any(target_os = "macos", target_os = "ios"))]
#[cfg(target_os = "ios")]
{
HwCodecConfig::default()
}
}
#[cfg(any(target_os = "windows", target_os = "linux"))]
#[cfg(not(any(target_os = "android", target_os = "ios")))]
pub fn get_set_value() -> Option<HwCodecConfig> {
let set = CONFIG_SET_BY_IPC.lock().unwrap().clone();
if set {
@@ -622,7 +624,7 @@ impl HwCodecConfig {
}
}
#[cfg(any(target_os = "windows", target_os = "linux"))]
#[cfg(not(any(target_os = "android", target_os = "ios")))]
pub fn already_set() -> bool {
CONFIG_SET_BY_IPC.lock().unwrap().clone()
}
@@ -690,7 +692,7 @@ pub fn check_available_hwcodec() -> String {
serde_json::to_string(&c).unwrap_or_default()
}
#[cfg(any(target_os = "windows", target_os = "linux"))]
#[cfg(not(any(target_os = "android", target_os = "ios")))]
pub fn start_check_process() {
if !enable_hwcodec_option() || HwCodecConfig::already_set() {
return;