mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-01-28 16:41:52 +08:00
refactor: 清理死代码和优化日志级别
- 删除未使用的函数和常量 - create_public_key_message (rustdesk/connection) - decode_audio_packet, AudioPacketHeader (web/audio_ws) - io_error_to_hid_error, close_device, close_all_devices (hid) - shutdown_rx (rustdesk/mod) - CONNECT_TIMEOUT_MS, RESP_ERR_SEND_FAILED - 调整日志级别 - Session lagged: warn -> debug - 移除 H264 NAL trace 日志 - 移除 Frame distribution lagged trace 日志 - 移除 absolute mouse report trace 日志 - 优化 broadcast channel 缓冲区大小 8 -> 16 - 修复条件编译 - static_files.rs: 添加 debug_assertions 条件
This commit is contained in:
@@ -140,7 +140,7 @@ impl AudioCapturer {
|
||||
/// Create a new audio capturer
|
||||
pub fn new(config: AudioConfig) -> Self {
|
||||
let (state_tx, state_rx) = watch::channel(CaptureState::Stopped);
|
||||
let (frame_tx, _) = broadcast::channel(32);
|
||||
let (frame_tx, _) = broadcast::channel(16); // Buffer size 16 for low latency
|
||||
|
||||
Self {
|
||||
config,
|
||||
|
||||
@@ -111,7 +111,7 @@ impl AudioStreamer {
|
||||
/// Create a new audio streamer with specified configuration
|
||||
pub fn with_config(config: AudioStreamerConfig) -> Self {
|
||||
let (state_tx, state_rx) = watch::channel(AudioStreamState::Stopped);
|
||||
let (opus_tx, _) = broadcast::channel(64);
|
||||
let (opus_tx, _) = broadcast::channel(16); // Buffer size 16 for low latency
|
||||
|
||||
Self {
|
||||
config: RwLock::new(config),
|
||||
|
||||
@@ -449,29 +449,6 @@ impl Ch9329Backend {
|
||||
self.port.lock().is_some()
|
||||
}
|
||||
|
||||
/// Convert I/O error to HidError with appropriate error code
|
||||
#[allow(dead_code)]
|
||||
fn io_error_to_hid_error(e: std::io::Error, operation: &str) -> AppError {
|
||||
let error_code = match e.kind() {
|
||||
std::io::ErrorKind::NotFound => "port_not_found",
|
||||
std::io::ErrorKind::PermissionDenied => "permission_denied",
|
||||
std::io::ErrorKind::TimedOut => "timeout",
|
||||
std::io::ErrorKind::BrokenPipe => "broken_pipe",
|
||||
_ => match e.raw_os_error() {
|
||||
Some(6) => "enxio", // ENXIO - no such device
|
||||
Some(19) => "enodev", // ENODEV - no such device
|
||||
Some(5) => "eio", // EIO - I/O error
|
||||
_ => "serial_error",
|
||||
},
|
||||
};
|
||||
|
||||
AppError::HidError {
|
||||
backend: "ch9329".to_string(),
|
||||
reason: format!("{}: {}", operation, e),
|
||||
error_code: error_code.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert serialport error to HidError
|
||||
fn serial_error_to_hid_error(e: serialport::Error, operation: &str) -> AppError {
|
||||
let error_code = match e.kind() {
|
||||
|
||||
@@ -284,31 +284,6 @@ impl OtgBackend {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Close a device (used when ESHUTDOWN is received)
|
||||
#[allow(dead_code)]
|
||||
fn close_device(&self, device_type: DeviceType) {
|
||||
let dev_mutex = match device_type {
|
||||
DeviceType::Keyboard => &self.keyboard_dev,
|
||||
DeviceType::MouseRelative => &self.mouse_rel_dev,
|
||||
DeviceType::MouseAbsolute => &self.mouse_abs_dev,
|
||||
};
|
||||
|
||||
let mut dev = dev_mutex.lock();
|
||||
if dev.is_some() {
|
||||
debug!("Closing {:?} device handle for recovery", device_type);
|
||||
*dev = None;
|
||||
}
|
||||
}
|
||||
|
||||
/// Close all device handles (for recovery)
|
||||
#[allow(dead_code)]
|
||||
fn close_all_devices(&self) {
|
||||
self.close_device(DeviceType::Keyboard);
|
||||
self.close_device(DeviceType::MouseRelative);
|
||||
self.close_device(DeviceType::MouseAbsolute);
|
||||
self.online.store(false, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
/// Open a HID device file with read/write access
|
||||
fn open_device(path: &PathBuf) -> Result<File> {
|
||||
OpenOptions::new()
|
||||
@@ -527,7 +502,6 @@ impl OtgBackend {
|
||||
Ok(_) => {
|
||||
self.online.store(true, Ordering::Relaxed);
|
||||
self.reset_error_count();
|
||||
trace!("Sent absolute mouse report: {:02X?}", data);
|
||||
Ok(())
|
||||
}
|
||||
Err(e) => {
|
||||
|
||||
@@ -28,8 +28,6 @@ use crate::utils::LogThrottler;
|
||||
const RESP_OK: u8 = 0x00;
|
||||
const RESP_ERR_HID_UNAVAILABLE: u8 = 0x01;
|
||||
const RESP_ERR_INVALID_MESSAGE: u8 = 0x02;
|
||||
#[allow(dead_code)]
|
||||
const RESP_ERR_SEND_FAILED: u8 = 0x03;
|
||||
|
||||
/// WebSocket HID upgrade handler
|
||||
pub async fn ws_hid_handler(ws: WebSocketUpgrade, State(state): State<Arc<AppState>>) -> Response {
|
||||
|
||||
@@ -723,16 +723,6 @@ impl Connection {
|
||||
}
|
||||
}
|
||||
|
||||
/// Create public key message (for legacy compatibility)
|
||||
fn create_public_key_message(&self) -> hbb::Message {
|
||||
hbb::Message {
|
||||
union: Some(message::Union::PublicKey(hbb::PublicKey {
|
||||
asymmetric_value: self.keypair.public_key_bytes().to_vec(),
|
||||
symmetric_value: vec![],
|
||||
})),
|
||||
}
|
||||
}
|
||||
|
||||
/// Handle peer's public key and negotiate session encryption
|
||||
/// After successful negotiation, send Hash message for password authentication
|
||||
async fn handle_peer_public_key(
|
||||
|
||||
@@ -383,12 +383,6 @@ impl RustDeskService {
|
||||
self.start().await
|
||||
}
|
||||
|
||||
/// Get a shutdown receiver for graceful shutdown handling
|
||||
#[allow(dead_code)]
|
||||
pub fn shutdown_rx(&self) -> broadcast::Receiver<()> {
|
||||
self.shutdown_tx.subscribe()
|
||||
}
|
||||
|
||||
/// Save keypair and UUID to config
|
||||
/// Returns the updated config if changes were made
|
||||
pub fn save_credentials(&self) -> Option<RustDeskConfig> {
|
||||
|
||||
@@ -31,10 +31,6 @@ const MIN_REG_TIMEOUT_MS: u64 = 3_000;
|
||||
/// Maximum registration timeout
|
||||
const MAX_REG_TIMEOUT_MS: u64 = 30_000;
|
||||
|
||||
/// Connection timeout
|
||||
#[allow(dead_code)]
|
||||
const CONNECT_TIMEOUT_MS: u64 = 18_000;
|
||||
|
||||
/// Timer interval for checking registration status
|
||||
const TIMER_INTERVAL_MS: u64 = 300;
|
||||
|
||||
@@ -682,7 +678,6 @@ impl AddrMangle {
|
||||
}
|
||||
|
||||
/// Decode bytes to SocketAddr using RustDesk's mangle algorithm
|
||||
#[allow(dead_code)]
|
||||
pub fn decode(bytes: &[u8]) -> Option<SocketAddr> {
|
||||
use std::convert::TryInto;
|
||||
use std::net::{Ipv4Addr, Ipv6Addr, SocketAddrV4};
|
||||
|
||||
@@ -167,7 +167,7 @@ impl MjpegStreamHandler {
|
||||
|
||||
/// Create handler with custom drop limit
|
||||
pub fn with_drop_limit(max_drop: u64) -> Self {
|
||||
let (frame_notify, _) = broadcast::channel(4); // Reduced from 16 for lower latency
|
||||
let (frame_notify, _) = broadcast::channel(16); // Buffer size 16 for low latency
|
||||
Self {
|
||||
current_frame: ArcSwap::from_pointee(None),
|
||||
frame_notify,
|
||||
|
||||
@@ -143,7 +143,7 @@ impl VideoCapturer {
|
||||
/// Create a new video capturer
|
||||
pub fn new(config: CaptureConfig) -> Self {
|
||||
let (state_tx, state_rx) = watch::channel(CaptureState::Stopped);
|
||||
let (frame_tx, _) = broadcast::channel(4); // Reduced from 64 for lower latency
|
||||
let (frame_tx, _) = broadcast::channel(16); // Buffer size 16 for low latency
|
||||
|
||||
Self {
|
||||
config,
|
||||
|
||||
@@ -314,7 +314,7 @@ impl SharedVideoPipeline {
|
||||
config.input_format
|
||||
);
|
||||
|
||||
let (frame_tx, _) = broadcast::channel(8); // Reduced from 64 for lower latency
|
||||
let (frame_tx, _) = broadcast::channel(16); // Reduced from 64 for lower latency
|
||||
let (running_tx, running_rx) = watch::channel(false);
|
||||
let nv12_size = (config.resolution.width * config.resolution.height * 3 / 2) as usize;
|
||||
let yuv420p_size = nv12_size; // Same size as NV12
|
||||
|
||||
@@ -452,9 +452,7 @@ impl Streamer {
|
||||
Ok(frame) => {
|
||||
mjpeg_handler.update_frame(frame);
|
||||
}
|
||||
Err(tokio::sync::broadcast::error::RecvError::Lagged(n)) => {
|
||||
trace!("Frame distribution lagged by {} frames", n);
|
||||
}
|
||||
Err(tokio::sync::broadcast::error::RecvError::Lagged(_)) => {}
|
||||
Err(tokio::sync::broadcast::error::RecvError::Closed) => {
|
||||
debug!("Frame channel closed");
|
||||
break;
|
||||
@@ -544,9 +542,7 @@ impl Streamer {
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(tokio::sync::broadcast::error::RecvError::Lagged(n)) => {
|
||||
trace!("Frame distribution lagged by {} frames", n);
|
||||
}
|
||||
Err(tokio::sync::broadcast::error::RecvError::Lagged(_)) => {}
|
||||
Err(tokio::sync::broadcast::error::RecvError::Closed) => {
|
||||
debug!("Frame channel closed");
|
||||
break;
|
||||
|
||||
@@ -180,42 +180,6 @@ fn encode_audio_packet(frame: &OpusFrame, stream_start: Instant) -> Vec<u8> {
|
||||
buf
|
||||
}
|
||||
|
||||
/// Decode audio packet from binary format (for testing/debugging)
|
||||
#[allow(dead_code)]
|
||||
pub fn decode_audio_packet(data: &[u8]) -> Option<AudioPacketHeader> {
|
||||
if data.len() < 15 {
|
||||
return None;
|
||||
}
|
||||
|
||||
if data[0] != AUDIO_PACKET_TYPE {
|
||||
return None;
|
||||
}
|
||||
|
||||
let timestamp = u32::from_le_bytes([data[1], data[2], data[3], data[4]]);
|
||||
let duration_ms = u16::from_le_bytes([data[5], data[6]]);
|
||||
let sequence = u32::from_le_bytes([data[7], data[8], data[9], data[10]]);
|
||||
let data_length = u32::from_le_bytes([data[11], data[12], data[13], data[14]]);
|
||||
|
||||
Some(AudioPacketHeader {
|
||||
packet_type: data[0],
|
||||
timestamp,
|
||||
duration_ms,
|
||||
sequence,
|
||||
data_length,
|
||||
})
|
||||
}
|
||||
|
||||
/// Audio packet header (for decoding/testing)
|
||||
#[derive(Debug, Clone)]
|
||||
#[allow(dead_code)]
|
||||
pub struct AudioPacketHeader {
|
||||
pub packet_type: u8,
|
||||
pub timestamp: u32,
|
||||
pub duration_ms: u16,
|
||||
pub sequence: u32,
|
||||
pub data_length: u32,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
@@ -4,9 +4,10 @@ use axum::{
|
||||
routing::get,
|
||||
Router,
|
||||
};
|
||||
#[cfg(debug_assertions)]
|
||||
use std::path::PathBuf;
|
||||
#[cfg(debug_assertions)]
|
||||
use std::sync::OnceLock;
|
||||
use tracing;
|
||||
|
||||
// Only embed assets in release mode
|
||||
#[cfg(not(debug_assertions))]
|
||||
@@ -22,6 +23,7 @@ pub struct StaticAssets;
|
||||
/// Get the base directory for static files
|
||||
/// In debug mode: relative to executable directory
|
||||
/// In release mode: not used (embedded assets)
|
||||
#[cfg(debug_assertions)]
|
||||
fn get_static_base_dir() -> PathBuf {
|
||||
static BASE_DIR: OnceLock<PathBuf> = OnceLock::new();
|
||||
BASE_DIR.get_or_init(|| {
|
||||
|
||||
@@ -383,7 +383,7 @@ pub struct PeerConnectionManager {
|
||||
impl PeerConnectionManager {
|
||||
/// Create a new peer connection manager
|
||||
pub fn new(config: WebRtcConfig) -> Self {
|
||||
let (frame_tx, _) = broadcast::channel(16);
|
||||
let (frame_tx, _) = broadcast::channel(16); // Buffer size 16 for low latency
|
||||
|
||||
Self {
|
||||
config,
|
||||
@@ -395,7 +395,7 @@ impl PeerConnectionManager {
|
||||
|
||||
/// Create a new peer connection manager with HID controller
|
||||
pub fn with_hid(config: WebRtcConfig, hid: Arc<HidController>) -> Self {
|
||||
let (frame_tx, _) = broadcast::channel(16);
|
||||
let (frame_tx, _) = broadcast::channel(16); // Buffer size 16 for low latency
|
||||
|
||||
Self {
|
||||
config,
|
||||
|
||||
@@ -339,7 +339,6 @@ impl UnifiedVideoTrack {
|
||||
_ => {}
|
||||
}
|
||||
|
||||
trace!("H264 NAL: type={} size={}", nal_type, nal.data.len());
|
||||
nals.push(nal.data.freeze());
|
||||
}
|
||||
|
||||
|
||||
@@ -573,7 +573,7 @@ impl UniversalSession {
|
||||
}
|
||||
}
|
||||
Err(broadcast::error::RecvError::Lagged(n)) => {
|
||||
warn!("Session {} lagged by {} frames", session_id, n);
|
||||
debug!("Session {} lagged by {} frames", session_id, n);
|
||||
}
|
||||
Err(broadcast::error::RecvError::Closed) => {
|
||||
info!("Video frame channel closed for session {}", session_id);
|
||||
|
||||
@@ -376,7 +376,6 @@ impl UniversalVideoTrack {
|
||||
_ => {}
|
||||
}
|
||||
|
||||
trace!("H264 NAL: type={} size={}", nal_type, nal.data.len());
|
||||
nals.push(nal.data.freeze());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user