mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-03-26 04:46:35 +08:00
fix: 补齐 ATX 控制器缺失接口并完成全项目 clippy -D warnings 修复
This commit is contained in:
@@ -108,18 +108,15 @@ impl TurnServer {
|
||||
/// Video codec preference
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
#[derive(Default)]
|
||||
pub enum VideoCodec {
|
||||
#[default]
|
||||
H264,
|
||||
VP8,
|
||||
VP9,
|
||||
AV1,
|
||||
}
|
||||
|
||||
impl Default for VideoCodec {
|
||||
fn default() -> Self {
|
||||
Self::H264
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for VideoCodec {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
|
||||
@@ -93,7 +93,6 @@ impl PeerConnection {
|
||||
urls: turn.urls.clone(),
|
||||
username: turn.username.clone(),
|
||||
credential: turn.credential.clone(),
|
||||
..Default::default()
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -330,9 +330,7 @@ impl OpusAudioTrack {
|
||||
stream_id.to_string(),
|
||||
));
|
||||
|
||||
Self {
|
||||
track,
|
||||
}
|
||||
Self { track }
|
||||
}
|
||||
|
||||
/// Get the underlying WebRTC track
|
||||
@@ -365,13 +363,10 @@ impl OpusAudioTrack {
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
self.track
|
||||
.write_sample(&sample)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
error!("Failed to write Opus sample: {}", e);
|
||||
AppError::WebRtcError(format!("Failed to write audio sample: {}", e))
|
||||
})
|
||||
self.track.write_sample(&sample).await.map_err(|e| {
|
||||
error!("Failed to write Opus sample: {}", e);
|
||||
AppError::WebRtcError(format!("Failed to write audio sample: {}", e))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -199,7 +199,7 @@ impl VideoTrack {
|
||||
let data = frame.data();
|
||||
let max_payload_size = 1200; // MTU - headers
|
||||
|
||||
let packet_count = (data.len() + max_payload_size - 1) / max_payload_size;
|
||||
let packet_count = data.len().div_ceil(max_payload_size);
|
||||
let mut bytes_sent = 0u64;
|
||||
|
||||
for i in 0..packet_count {
|
||||
|
||||
@@ -292,7 +292,6 @@ impl UniversalSession {
|
||||
urls: turn.urls.clone(),
|
||||
username: turn.username.clone(),
|
||||
credential: turn.credential.clone(),
|
||||
..Default::default()
|
||||
});
|
||||
}
|
||||
|
||||
@@ -430,7 +429,9 @@ impl UniversalSession {
|
||||
let candidate = IceCandidate {
|
||||
candidate: candidate_str,
|
||||
sdp_mid: candidate_json.as_ref().and_then(|j| j.sdp_mid.clone()),
|
||||
sdp_mline_index: candidate_json.as_ref().and_then(|j| j.sdp_mline_index),
|
||||
sdp_mline_index: candidate_json
|
||||
.as_ref()
|
||||
.and_then(|j| j.sdp_mline_index),
|
||||
username_fragment: candidate_json
|
||||
.as_ref()
|
||||
.and_then(|j| j.username_fragment.clone()),
|
||||
@@ -615,20 +616,15 @@ impl UniversalSession {
|
||||
};
|
||||
|
||||
// Verify codec matches
|
||||
let frame_codec = match encoded_frame.codec {
|
||||
VideoEncoderType::H264 => VideoEncoderType::H264,
|
||||
VideoEncoderType::H265 => VideoEncoderType::H265,
|
||||
VideoEncoderType::VP8 => VideoEncoderType::VP8,
|
||||
VideoEncoderType::VP9 => VideoEncoderType::VP9,
|
||||
};
|
||||
let frame_codec = encoded_frame.codec;
|
||||
|
||||
if frame_codec != expected_codec {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Debug log for H265 frames
|
||||
if expected_codec == VideoEncoderType::H265 {
|
||||
if encoded_frame.is_keyframe || frames_sent % 30 == 0 {
|
||||
if expected_codec == VideoEncoderType::H265
|
||||
&& (encoded_frame.is_keyframe || frames_sent.is_multiple_of(30)) {
|
||||
debug!(
|
||||
"[Session-H265] Received frame #{}: size={}, keyframe={}, seq={}",
|
||||
frames_sent,
|
||||
@@ -637,7 +633,6 @@ impl UniversalSession {
|
||||
encoded_frame.sequence
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure decoder starts from a keyframe and recover on gaps.
|
||||
let mut gap_detected = false;
|
||||
@@ -768,7 +763,7 @@ impl UniversalSession {
|
||||
// 20ms at 48kHz = 960 samples
|
||||
let samples = 960u32;
|
||||
if let Err(e) = audio_track.write_packet(&opus_frame.data, samples).await {
|
||||
if packets_sent % 100 == 0 {
|
||||
if packets_sent.is_multiple_of(100) {
|
||||
debug!("Failed to write audio packet: {}", e);
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -285,7 +285,7 @@ impl UniversalVideoTrack {
|
||||
}
|
||||
|
||||
/// Get current statistics
|
||||
|
||||
///
|
||||
/// Write an encoded frame to the track
|
||||
///
|
||||
/// Handles codec-specific processing:
|
||||
@@ -464,7 +464,6 @@ impl UniversalVideoTrack {
|
||||
if let Err(e) = rtp_track.write_rtp(&packet).await {
|
||||
trace!("H265 write_rtp failed: {}", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -35,8 +35,8 @@ use tokio::sync::RwLock;
|
||||
use tracing::{debug, info, trace, warn};
|
||||
|
||||
use crate::audio::{AudioController, OpusFrame};
|
||||
use crate::events::EventBus;
|
||||
use crate::error::{AppError, Result};
|
||||
use crate::events::EventBus;
|
||||
use crate::hid::HidController;
|
||||
use crate::video::encoder::registry::EncoderBackend;
|
||||
use crate::video::encoder::registry::VideoEncoderType;
|
||||
@@ -270,7 +270,6 @@ impl WebRtcStreamer {
|
||||
bitrate_preset: config.bitrate_preset,
|
||||
fps: config.fps,
|
||||
encoder_backend: config.encoder_backend,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
info!("Creating shared video pipeline for {:?}", codec);
|
||||
@@ -311,7 +310,9 @@ impl WebRtcStreamer {
|
||||
}
|
||||
drop(pipeline_guard);
|
||||
|
||||
info!("Video pipeline stopped, but keeping capture config for new sessions");
|
||||
info!(
|
||||
"Video pipeline stopped, but keeping capture config for new sessions"
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -926,10 +927,7 @@ impl WebRtcStreamer {
|
||||
let pipeline = pipeline_for_callback.clone();
|
||||
let sid = sid.clone();
|
||||
tokio::spawn(async move {
|
||||
info!(
|
||||
"Requesting keyframe for session {} after reconnect",
|
||||
sid
|
||||
);
|
||||
info!("Requesting keyframe for session {} after reconnect", sid);
|
||||
pipeline.request_keyframe().await;
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user