refactor: 精简运行时重复初始化

统一服务与 CLI 的数据库初始化入口,由视频流管理器负责 WebRTC 采集源同步,并将 MSD 目录创建收敛到控制器内部。
This commit is contained in:
mofeng-git
2026-08-26 11:37:39 +08:00
parent 486f3887c2
commit 0054100414
6 changed files with 70 additions and 81 deletions

View File

@@ -195,25 +195,15 @@ impl VideoStreamManager {
info!("Initializing video stream manager with mode: {:?}", mode);
*self.mode.write().await = mode.clone();
// Check if streamer is already initialized (capturer exists)
let needs_init = self.streamer.state().await == StreamerState::Uninitialized;
// A failed fixed-device configuration can leave the streamer in a transient
// state without a capture device. Treat that the same as an uninitialized
// streamer so the advertised auto-detection fallback actually runs.
let state = self.streamer.state().await;
let (device_path, _, _, _, _) = self.streamer.current_capture_config().await;
let needs_init = state == StreamerState::Uninitialized || device_path.is_none();
if needs_init {
match mode {
StreamMode::Mjpeg => {
// Initialize MJPEG streamer
if let Err(e) = self.streamer.init_auto().await {
warn!("Failed to auto-initialize MJPEG streamer: {}", e);
}
}
StreamMode::WebRTC => {
// WebRTC is initialized on-demand when clients connect
// But we still need to initialize the video capture
if let Err(e) = self.streamer.init_auto().await {
warn!("Failed to auto-initialize video capture for WebRTC: {}", e);
}
}
}
self.streamer.init_auto().await?;
}
self.sync_webrtc_capture_source("after init").await;