From 23deae0e523557e9bfbb8fe0e48322a9f7505bd7 Mon Sep 17 00:00:00 2001 From: 21pages Date: Tue, 19 Jul 2022 18:14:34 +0800 Subject: [PATCH] hwcodec: remove bad MY_DECODER_STATE When reset, the new of the decoder will be after it's drop Signed-off-by: 21pages --- libs/scrap/src/common/codec.rs | 36 ++++++++------------------------ libs/scrap/src/common/hwcodec.rs | 2 +- 2 files changed, 10 insertions(+), 28 deletions(-) diff --git a/libs/scrap/src/common/codec.rs b/libs/scrap/src/common/codec.rs index 1a18a79c3..f0bd1c5f7 100644 --- a/libs/scrap/src/common/codec.rs +++ b/libs/scrap/src/common/codec.rs @@ -25,7 +25,6 @@ use hbb_common::{ #[cfg(feature = "hwcodec")] lazy_static::lazy_static! { static ref PEER_DECODER_STATES: Arc>> = Default::default(); - static ref MY_DECODER_STATE: Arc> = Default::default(); } const SCORE_VPX: i32 = 90; @@ -238,25 +237,18 @@ impl Encoder { } } -#[cfg(feature = "hwcodec")] -impl Drop for Decoder { - fn drop(&mut self) { - *MY_DECODER_STATE.lock().unwrap() = VideoCodecState { - score_vpx: SCORE_VPX, - ..Default::default() - }; - } -} - impl Decoder { pub fn video_codec_state(_id: &str) -> VideoCodecState { - // video_codec_state is mainted by creation and destruction of Decoder. - // It has been ensured to use after Decoder's creation. #[cfg(feature = "hwcodec")] if check_hwcodec_config() { - let mut state = MY_DECODER_STATE.lock().unwrap(); - state.perfer = Self::codec_preference(_id).into(); - state.clone() + let best = HwDecoder::best(); + VideoCodecState { + score_vpx: SCORE_VPX, + score_h264: best.h264.map_or(0, |c| c.score), + score_h265: best.h265.map_or(0, |c| c.score), + perfer: Self::codec_preference(_id).into(), + ..Default::default() + } } else { return VideoCodecState { score_vpx: SCORE_VPX, @@ -272,23 +264,13 @@ impl Decoder { pub fn new(config: DecoderCfg) -> Decoder { let vpx = VpxDecoder::new(config.vpx).unwrap(); - let decoder = Decoder { + Decoder { vpx, #[cfg(feature = "hwcodec")] hw: HwDecoder::new_decoders(), #[cfg(feature = "hwcodec")] i420: vec![], - }; - - #[cfg(feature = "hwcodec")] - { - let mut state = MY_DECODER_STATE.lock().unwrap(); - state.score_vpx = SCORE_VPX; - state.score_h264 = decoder.hw.h264.as_ref().map_or(0, |d| d.info.score); - state.score_h265 = decoder.hw.h265.as_ref().map_or(0, |d| d.info.score); } - - decoder } pub fn handle_video_frame( diff --git a/libs/scrap/src/common/hwcodec.rs b/libs/scrap/src/common/hwcodec.rs index c2c853956..c065d811d 100644 --- a/libs/scrap/src/common/hwcodec.rs +++ b/libs/scrap/src/common/hwcodec.rs @@ -178,7 +178,7 @@ pub struct HwDecoders { } impl HwDecoder { - fn best() -> CodecInfos { + pub fn best() -> CodecInfos { get_config(CFG_KEY_DECODER).unwrap_or(CodecInfos { h264: None, h265: None,