mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-04-30 01:46:37 +08:00
feat: 完善架构优化性能
- 调整音视频架构,提升 RKMPP 编码 MJPEG-->H264 性能,同时解决丢帧马赛克问题; - 删除多用户逻辑,只保留单用户,支持设置 web 单会话; - 修复删除体验不好的的回退逻辑,前端页面菜单位置微调; - 增加 OTG USB 设备动态调整功能; - 修复 mdns 问题,webrtc 视频切换更顺畅。
This commit is contained in:
@@ -157,6 +157,8 @@ pub struct MjpegStreamHandler {
|
||||
max_drop_same_frames: AtomicU64,
|
||||
/// JPEG encoder for non-JPEG input formats
|
||||
jpeg_encoder: ParkingMutex<Option<JpegEncoder>>,
|
||||
/// JPEG quality for software encoding (1-100)
|
||||
jpeg_quality: AtomicU64,
|
||||
}
|
||||
|
||||
impl MjpegStreamHandler {
|
||||
@@ -179,9 +181,16 @@ impl MjpegStreamHandler {
|
||||
last_frame_ts: ParkingRwLock::new(None),
|
||||
dropped_same_frames: AtomicU64::new(0),
|
||||
max_drop_same_frames: AtomicU64::new(max_drop),
|
||||
jpeg_quality: AtomicU64::new(80),
|
||||
}
|
||||
}
|
||||
|
||||
/// Set JPEG quality for software encoding (1-100)
|
||||
pub fn set_jpeg_quality(&self, quality: u8) {
|
||||
let clamped = quality.clamp(1, 100) as u64;
|
||||
self.jpeg_quality.store(clamped, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
/// Update current frame
|
||||
pub fn update_frame(&self, frame: VideoFrame) {
|
||||
// Fast path: if no MJPEG clients are connected, do minimal bookkeeping and avoid
|
||||
@@ -260,23 +269,24 @@ impl MjpegStreamHandler {
|
||||
fn encode_to_jpeg(&self, frame: &VideoFrame) -> Result<VideoFrame, String> {
|
||||
let resolution = frame.resolution;
|
||||
let sequence = self.sequence.load(Ordering::Relaxed);
|
||||
let desired_quality = self.jpeg_quality.load(Ordering::Relaxed) as u32;
|
||||
|
||||
// Get or create encoder
|
||||
let mut encoder_guard = self.jpeg_encoder.lock();
|
||||
let encoder = encoder_guard.get_or_insert_with(|| {
|
||||
let config = EncoderConfig::jpeg(resolution, 85);
|
||||
let config = EncoderConfig::jpeg(resolution, desired_quality);
|
||||
match JpegEncoder::new(config) {
|
||||
Ok(enc) => {
|
||||
debug!(
|
||||
"Created JPEG encoder for MJPEG stream: {}x{}",
|
||||
resolution.width, resolution.height
|
||||
"Created JPEG encoder for MJPEG stream: {}x{} (q={})",
|
||||
resolution.width, resolution.height, desired_quality
|
||||
);
|
||||
enc
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("Failed to create JPEG encoder: {}, using default", e);
|
||||
// Try with default config
|
||||
JpegEncoder::new(EncoderConfig::jpeg(resolution, 85))
|
||||
JpegEncoder::new(EncoderConfig::jpeg(resolution, desired_quality))
|
||||
.expect("Failed to create default JPEG encoder")
|
||||
}
|
||||
}
|
||||
@@ -288,9 +298,16 @@ impl MjpegStreamHandler {
|
||||
"Resolution changed, recreating JPEG encoder: {}x{}",
|
||||
resolution.width, resolution.height
|
||||
);
|
||||
let config = EncoderConfig::jpeg(resolution, 85);
|
||||
let config = EncoderConfig::jpeg(resolution, desired_quality);
|
||||
*encoder =
|
||||
JpegEncoder::new(config).map_err(|e| format!("Failed to create encoder: {}", e))?;
|
||||
} else if encoder.config().quality != desired_quality {
|
||||
if let Err(e) = encoder.set_quality(desired_quality) {
|
||||
warn!("Failed to set JPEG quality: {}, recreating encoder", e);
|
||||
let config = EncoderConfig::jpeg(resolution, desired_quality);
|
||||
*encoder = JpegEncoder::new(config)
|
||||
.map_err(|e| format!("Failed to create encoder: {}", e))?;
|
||||
}
|
||||
}
|
||||
|
||||
// Encode based on input format
|
||||
|
||||
Reference in New Issue
Block a user