From 9cce0798b635e652ca14d20ec04cb27f5f761cdb Mon Sep 17 00:00:00 2001 From: 21pages Date: Fri, 19 May 2023 12:03:16 +0800 Subject: [PATCH] set hw_pixfmt nv12 and wait more time for check porcess Signed-off-by: 21pages --- libs/scrap/src/common/hwcodec.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/libs/scrap/src/common/hwcodec.rs b/libs/scrap/src/common/hwcodec.rs index 8daa6551c..cda849f4e 100644 --- a/libs/scrap/src/common/hwcodec.rs +++ b/libs/scrap/src/common/hwcodec.rs @@ -23,7 +23,7 @@ use hwcodec::{ const CFG_KEY_ENCODER: &str = "bestHwEncoders"; const CFG_KEY_DECODER: &str = "bestHwDecoders"; -const DEFAULT_PIXFMT: AVPixelFormat = AVPixelFormat::AV_PIX_FMT_YUV420P; +const DEFAULT_PIXFMT: AVPixelFormat = AVPixelFormat::AV_PIX_FMT_NV12; pub const DEFAULT_TIME_BASE: [i32; 2] = [1, 30]; const DEFAULT_GOP: i32 = i32::MAX; const DEFAULT_HW_QUALITY: Quality = Quality_Default; @@ -327,6 +327,8 @@ pub fn check_config_process() { use hbb_common::sysinfo::{ProcessExt, System, SystemExt}; std::thread::spawn(move || { + // Remove to avoid checking process errors + // But when the program is just started, the configuration file has not been updated, and the new connection will read an empty configuration HwCodecConfig::remove(); if let Ok(exe) = std::env::current_exe() { if let Some(file_name) = exe.file_name().to_owned() { @@ -339,9 +341,16 @@ pub fn check_config_process() { } } if let Ok(mut child) = std::process::Command::new(exe).arg(arg).spawn() { - let second = 3; - std::thread::sleep(std::time::Duration::from_secs(second)); - // kill: Different platforms have different results + // wait up to 10 seconds + for _ in 0..10 { + std::thread::sleep(std::time::Duration::from_secs(1)); + if let Ok(Some(status)) = child.try_wait() { + if status.success() { + HwCodecConfig::refresh(); + } + break; + } + } allow_err!(child.kill()); std::thread::sleep(std::time::Duration::from_millis(30)); match child.try_wait() {