From ca8059664ef4b56a14a927be1aae3f427280f0fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Ant=C3=B4nio=20Cardoso?= Date: Tue, 1 Oct 2024 16:18:14 -0300 Subject: [PATCH] src: lib: stream: sink: rtsp_sink: Better deal with socket file --- src/lib/stream/sink/rtsp_sink.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/lib/stream/sink/rtsp_sink.rs b/src/lib/stream/sink/rtsp_sink.rs index 91843b92..e0634f9b 100644 --- a/src/lib/stream/sink/rtsp_sink.rs +++ b/src/lib/stream/sink/rtsp_sink.rs @@ -29,8 +29,6 @@ impl SinkInterface for RtspSink { ) -> Result<()> { let sink_id = &self.get_id(); - let _ = std::fs::remove_file(&self.socket_path); // Remove if already exists - // Set Tee's src pad if self.tee_src_pad.is_some() { return Err(anyhow!( @@ -149,10 +147,6 @@ impl SinkInterface for RtspSink { #[instrument(level = "debug", skip(self, pipeline))] fn unlink(&self, pipeline: &gst::Pipeline, pipeline_id: &uuid::Uuid) -> Result<()> { - if let Err(error) = std::fs::remove_file(&self.socket_path) { - warn!("Failed removing the RTSP Sink socket file. Reason: {error:?}"); - } - let Some(tee_src_pad) = &self.tee_src_pad else { warn!("Tried to unlink Sink from a pipeline without a Tee src pad."); return Ok(()); @@ -201,6 +195,8 @@ impl SinkInterface for RtspSink { warn!("Failed to set RtspSink's to NULL: {state_err:#?}"); } + let _ = std::fs::remove_file(&self.socket_path); + Ok(()) } @@ -248,7 +244,15 @@ impl RtspSink { "Failed to find RTSP compatible address. Example: \"rtsp://0.0.0.0:8554/test\"", )?; - let socket_path = format!("/tmp/{id}"); + let socket_path = { + let path = std::env::temp_dir().join(format!("{id}.sock")); + + if path.try_exists()? { + std::fs::remove_file(path.clone())?; + } + path.to_string_lossy().to_string() + }; + let sink = gst::ElementFactory::make("shmsink") .property_from_str("socket-path", &socket_path) .property("sync", false)