From 5e2a1f88c3ac371246403b11d8253fbd74b2af64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Ant=C3=B4nio=20Cardoso?= Date: Thu, 10 Aug 2023 14:53:59 -0300 Subject: [PATCH] src: stream, rtsp: Remove stream if the path is already in use --- src/stream/pipeline/mod.rs | 3 +++ src/stream/rtsp/rtsp_server.rs | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/src/stream/pipeline/mod.rs b/src/stream/pipeline/mod.rs index 2a426093..260dbd77 100644 --- a/src/stream/pipeline/mod.rs +++ b/src/stream/pipeline/mod.rs @@ -188,6 +188,9 @@ impl PipelineState { debug!("caps: {:#?}", caps.to_string()); + // In case it exisits, try to remove it first, but skip the result + let _ = RTSPServer::stop_pipeline(&sink.path()); + RTSPServer::add_pipeline(&sink.path(), &sink.socket_path(), caps)?; RTSPServer::start_pipeline(&sink.path())?; diff --git a/src/stream/rtsp/rtsp_server.rs b/src/stream/rtsp/rtsp_server.rs index 0e8f23fe..3c6ea02d 100644 --- a/src/stream/rtsp/rtsp_server.rs +++ b/src/stream/rtsp/rtsp_server.rs @@ -227,6 +227,10 @@ impl RTSPServer { pub fn stop_pipeline(path: &str) -> Result<()> { let mut rtsp_server = RTSP_SERVER.as_ref().lock().unwrap(); + if !rtsp_server.path_to_factory.contains_key(path) { + return Err(anyhow!("Path {path:?} not known.")); + } + // Much like HTTP servers, RTSP servers have multiple endpoints that // provide different streams. Here, we ask our server to give // us a reference to his list of endpoints, so we can add our @@ -240,6 +244,8 @@ impl RTSPServer { rtsp_server.path_to_factory.remove(path); + debug!("RTSP {path:?} removed."); + Ok(()) } }