mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-03-26 04:46:35 +08:00
fix: 修复 rtsp 服务连接错误
This commit is contained in:
@@ -250,6 +250,33 @@ impl WebRtcStreamer {
|
||||
}
|
||||
}
|
||||
|
||||
fn should_stop_pipeline(session_count: usize, subscriber_count: usize) -> bool {
|
||||
session_count == 0 && subscriber_count == 0
|
||||
}
|
||||
|
||||
async fn stop_pipeline_if_idle(&self, reason: &str) {
|
||||
let session_count = self.sessions.read().await.len();
|
||||
let pipeline = self.video_pipeline.read().await.clone();
|
||||
|
||||
let Some(pipeline) = pipeline else {
|
||||
return;
|
||||
};
|
||||
|
||||
let subscriber_count = pipeline.subscriber_count();
|
||||
if Self::should_stop_pipeline(session_count, subscriber_count) {
|
||||
info!(
|
||||
"{} stopping video pipeline (sessions={}, subscribers={})",
|
||||
reason, session_count, subscriber_count
|
||||
);
|
||||
pipeline.stop();
|
||||
} else {
|
||||
debug!(
|
||||
"Keeping video pipeline alive (reason={}, sessions={}, subscribers={})",
|
||||
reason, session_count, subscriber_count
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Ensure video pipeline is initialized and running
|
||||
async fn ensure_video_pipeline(self: &Arc<Self>) -> Result<Arc<SharedVideoPipeline>> {
|
||||
let mut pipeline_guard = self.video_pipeline.write().await;
|
||||
@@ -740,13 +767,7 @@ impl WebRtcStreamer {
|
||||
session.close().await?;
|
||||
}
|
||||
|
||||
// Stop pipeline if no more sessions
|
||||
if self.sessions.read().await.is_empty() {
|
||||
if let Some(ref pipeline) = *self.video_pipeline.read().await {
|
||||
info!("No more sessions, stopping video pipeline");
|
||||
pipeline.stop();
|
||||
}
|
||||
}
|
||||
self.stop_pipeline_if_idle("After close_session").await;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -763,11 +784,8 @@ impl WebRtcStreamer {
|
||||
}
|
||||
}
|
||||
|
||||
// Stop pipeline
|
||||
drop(sessions);
|
||||
if let Some(ref pipeline) = *self.video_pipeline.read().await {
|
||||
pipeline.stop();
|
||||
}
|
||||
self.stop_pipeline_if_idle("After close_all_sessions").await;
|
||||
|
||||
count
|
||||
}
|
||||
@@ -826,14 +844,9 @@ impl WebRtcStreamer {
|
||||
sessions.remove(id);
|
||||
}
|
||||
|
||||
// Stop pipeline if no more sessions
|
||||
if sessions.is_empty() {
|
||||
drop(sessions);
|
||||
if let Some(ref pipeline) = *self.video_pipeline.read().await {
|
||||
info!("No more sessions after cleanup, stopping video pipeline");
|
||||
pipeline.stop();
|
||||
}
|
||||
}
|
||||
drop(sessions);
|
||||
self.stop_pipeline_if_idle("After cleanup_closed_sessions")
|
||||
.await;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -990,4 +1003,12 @@ mod tests {
|
||||
let codecs = streamer.supported_video_codecs();
|
||||
assert!(codecs.contains(&VideoCodecType::H264));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stop_pipeline_requires_no_sessions_and_no_subscribers() {
|
||||
assert!(WebRtcStreamer::should_stop_pipeline(0, 0));
|
||||
assert!(!WebRtcStreamer::should_stop_pipeline(1, 0));
|
||||
assert!(!WebRtcStreamer::should_stop_pipeline(0, 1));
|
||||
assert!(!WebRtcStreamer::should_stop_pipeline(2, 3));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user