Skip to content

Commit

Permalink
src: stream, rtsp: Remove stream if the path is already in use
Browse files Browse the repository at this point in the history
  • Loading branch information
joaoantoniocardoso authored and patrickelectric committed Aug 10, 2023
1 parent b4ad9c4 commit 5e2a1f8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/stream/pipeline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())?;
Expand Down
6 changes: 6 additions & 0 deletions src/stream/rtsp/rtsp_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -240,6 +244,8 @@ impl RTSPServer {

rtsp_server.path_to_factory.remove(path);

debug!("RTSP {path:?} removed.");

Ok(())
}
}

0 comments on commit 5e2a1f8

Please sign in to comment.