opt supported encoding update, consider multi connections (#7978)

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages
2024-05-08 20:31:39 +08:00
committed by GitHub
parent 1b0a3e610e
commit 5ba1c2587d
5 changed files with 49 additions and 31 deletions

View File

@@ -15,7 +15,7 @@ use crate::{
aom::{self, AomDecoder, AomEncoder, AomEncoderConfig},
common::GoogleImage,
vpxcodec::{self, VpxDecoder, VpxDecoderConfig, VpxEncoder, VpxEncoderConfig, VpxVideoCodecId},
CodecFormat, CodecName, EncodeInput, EncodeYuvFormat, ImageRgb,
CodecFormat, EncodeInput, EncodeYuvFormat, ImageRgb,
};
use hbb_common::{
@@ -38,6 +38,7 @@ lazy_static::lazy_static! {
static ref PEER_DECODINGS: Arc<Mutex<HashMap<i32, SupportedDecoding>>> = Default::default();
static ref ENCODE_CODEC_FORMAT: Arc<Mutex<CodecFormat>> = Arc::new(Mutex::new(CodecFormat::VP9));
static ref THREAD_LOG_TIME: Arc<Mutex<Option<Instant>>> = Arc::new(Mutex::new(None));
static ref USABLE_ENCODING: Arc<Mutex<Option<SupportedEncoding>>> = Arc::new(Mutex::new(None));
}
pub const ENCODE_NEED_SWITCH: &'static str = "ENCODE_NEED_SWITCH";
@@ -235,6 +236,13 @@ impl Encoder {
})
.map(|(_, s)| s.prefer)
.collect();
*USABLE_ENCODING.lock().unwrap() = Some(SupportedEncoding {
vp8: vp8_useable,
av1: av1_useable,
h264: h264_useable,
h265: h265_useable,
..Default::default()
});
// find the most frequent preference
let mut counts = Vec::new();
for pref in &preferences {
@@ -323,6 +331,10 @@ impl Encoder {
encoding
}
pub fn usable_encoding() -> Option<SupportedEncoding> {
USABLE_ENCODING.lock().unwrap().clone()
}
pub fn set_fallback(config: &EncoderCfg) {
let format = match config {
EncoderCfg::VPX(vpx) => match vpx.codec {

View File

@@ -2,9 +2,7 @@ use crate::CodecFormat;
#[cfg(feature = "hwcodec")]
use hbb_common::anyhow::anyhow;
use hbb_common::{
bail, chrono,
config::Config,
log,
bail, chrono, log,
message_proto::{message, video_frame, EncodedVideoFrame, Message},
ResultType,
};

View File

@@ -6,7 +6,7 @@ use std::{
use crate::{
codec::{base_bitrate, enable_vram_option, EncoderApi, EncoderCfg, Quality},
AdapterDevice, CodecFormat, CodecName, EncodeInput, EncodeYuvFormat, Pixfmt,
AdapterDevice, CodecFormat, EncodeInput, EncodeYuvFormat, Pixfmt,
};
use hbb_common::{
anyhow::{anyhow, bail, Context},
@@ -284,10 +284,6 @@ impl VRamEncoder {
log::info!("set display#{display} not use vram encode to {not_use}");
ENOCDE_NOT_USE.lock().unwrap().insert(display, not_use);
}
pub fn not_use() -> bool {
ENOCDE_NOT_USE.lock().unwrap().iter().any(|v| *v.1)
}
}
pub struct VRamDecoder {