refactor: 重构 ffmpeg 编码器探测模块

This commit is contained in:
mofeng-git
2026-03-22 12:57:47 +08:00
parent e229f35777
commit 0db287bf55
13 changed files with 704 additions and 568 deletions

View File

@@ -221,23 +221,11 @@ impl WebRtcStreamer {
use crate::video::encoder::registry::EncoderRegistry;
let registry = EncoderRegistry::global();
let mut codecs = vec![];
// H264 always available (has software fallback)
codecs.push(VideoCodecType::H264);
// Check hardware codecs
if registry.is_format_available(VideoEncoderType::H265, true) {
codecs.push(VideoCodecType::H265);
}
if registry.is_format_available(VideoEncoderType::VP8, true) {
codecs.push(VideoCodecType::VP8);
}
if registry.is_format_available(VideoEncoderType::VP9, true) {
codecs.push(VideoCodecType::VP9);
}
codecs
VideoEncoderType::ordered()
.into_iter()
.filter(|codec| registry.is_codec_available(*codec))
.map(Self::encoder_type_to_codec_type)
.collect()
}
/// Convert VideoCodecType to VideoEncoderType
@@ -250,6 +238,15 @@ impl WebRtcStreamer {
}
}
fn encoder_type_to_codec_type(codec: VideoEncoderType) -> VideoCodecType {
match codec {
VideoEncoderType::H264 => VideoCodecType::H264,
VideoEncoderType::H265 => VideoCodecType::H265,
VideoEncoderType::VP8 => VideoCodecType::VP8,
VideoEncoderType::VP9 => VideoCodecType::VP9,
}
}
fn should_stop_pipeline(session_count: usize, subscriber_count: usize) -> bool {
session_count == 0 && subscriber_count == 0
}
@@ -577,7 +574,7 @@ impl WebRtcStreamer {
VideoCodecType::VP9 => VideoEncoderType::VP9,
};
EncoderRegistry::global()
.best_encoder(codec_type, false)
.best_available_encoder(codec_type)
.map(|e| e.is_hardware)
.unwrap_or(false)
}