perf(rustdesk): 优化视频流性能和修复管道重启问题

- 使用 bounded channel(4) 替代 unbounded channel 提供背压控制
- 配置 protobuf 使用 bytes::Bytes 类型实现零拷贝
- 添加 encode_frame_bytes_zero_copy 方法避免帧数据拷贝
- 预分配 128KB 发送缓冲区减少内存分配
- 添加 write_frame_buffered 函数复用缓冲区
- 修复视频管道重启后 RustDesk 连接不恢复的问题
- 实现双层循环自动重新订阅新管道
- 修复 WebRTC set_bitrate_preset 中 video_frame_tx 被清除的问题
- 删除冗余的 RegisterPeer 日志
This commit is contained in:
mofeng-git
2026-01-02 18:53:05 +08:00
parent 28ecf951df
commit 427751da24
6 changed files with 185 additions and 80 deletions

View File

@@ -895,6 +895,9 @@ impl WebRtcStreamer {
preset
);
// Save video_frame_tx BEFORE stopping pipeline (monitor task will clear it)
let saved_frame_tx = self.video_frame_tx.read().await.clone();
// Stop existing pipeline
if let Some(ref pipeline) = *self.video_pipeline.read().await {
pipeline.stop();
@@ -907,13 +910,16 @@ impl WebRtcStreamer {
*self.video_pipeline.write().await = None;
// Recreate pipeline with new config if we have a frame source
if let Some(ref tx) = *self.video_frame_tx.read().await {
if let Some(tx) = saved_frame_tx {
// Get existing sessions that need to be reconnected
let session_ids: Vec<String> = self.sessions.read().await.keys().cloned().collect();
if !session_ids.is_empty() {
// Restore video_frame_tx before recreating pipeline
*self.video_frame_tx.write().await = Some(tx.clone());
// Recreate pipeline
let pipeline = self.ensure_video_pipeline(tx.clone()).await?;
let pipeline = self.ensure_video_pipeline(tx).await?;
// Reconnect all sessions to new pipeline
let sessions = self.sessions.read().await;