scrap: ensure video_handler's creation before client start

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages
2022-06-09 17:14:26 +08:00
parent 2a91fb842d
commit feaadcfc96
3 changed files with 72 additions and 45 deletions

View File

@@ -137,29 +137,30 @@ impl EncoderApi for HwEncoder {
}
impl HwEncoder {
pub fn best() -> CodecInfos {
pub fn best(force_reset: bool) -> CodecInfos {
let key = "bestHwEncoders";
match get_config(key) {
Ok(config) => config,
Err(_) => {
let ctx = EncodeContext {
name: String::from(""),
width: 1920,
height: 1080,
pixfmt: DEFAULT_PIXFMT,
align: HW_STRIDE_ALIGN as _,
bitrate: 0,
timebase: DEFAULT_TIME_BASE,
gop: DEFAULT_GOP,
quality: DEFAULT_HW_QUALITY,
rc: DEFAULT_RC,
};
let encoders = CodecInfo::score(Encoder::avaliable_encoders(ctx));
let _ = set_config(key, &encoders)
.map_err(|e| log::error!("{:?}", e))
.ok();
encoders
}
let config = get_config(key);
if !force_reset && config.is_ok() {
config.unwrap()
} else {
let ctx = EncodeContext {
name: String::from(""),
width: 1920,
height: 1080,
pixfmt: DEFAULT_PIXFMT,
align: HW_STRIDE_ALIGN as _,
bitrate: 0,
timebase: DEFAULT_TIME_BASE,
gop: DEFAULT_GOP,
quality: DEFAULT_HW_QUALITY,
rc: DEFAULT_RC,
};
let encoders = CodecInfo::score(Encoder::avaliable_encoders(ctx));
let _ = set_config(key, &encoders)
.map_err(|e| log::error!("{:?}", e))
.ok();
encoders
}
}
@@ -234,7 +235,7 @@ pub struct HwDecoders {
impl HwDecoder {
/// H264, H265 decoder info with the highest score.
pub fn best(force_reset: bool) -> CodecInfos {
fn best(force_reset: bool) -> CodecInfos {
let key = "bestHwDecoders";
let config = get_config(key);
if !force_reset && config.is_ok() {
@@ -268,7 +269,6 @@ impl HwDecoder {
}
if fail {
HwDecoder::best(true);
// TODO: notify encoder
}
if h264.is_some() {