Skip to content

Commit

Permalink
src: lib: stream: sink: rtsp_sink: Better deal with socket file
Browse files Browse the repository at this point in the history
  • Loading branch information
joaoantoniocardoso committed Oct 1, 2024
1 parent 432a7c5 commit ca80596
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/lib/stream/sink/rtsp_sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down Expand Up @@ -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(());
Expand Down Expand Up @@ -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(())
}

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ca80596

Please sign in to comment.