From 33fc16f38cc4e3c06a891f2f2402f7088eb33325 Mon Sep 17 00:00:00 2001 From: Muaz Ahmad Date: Thu, 24 Aug 2023 12:51:12 +0500 Subject: [PATCH] change cleanup to check for active stream (prevents segment wipe on reconnect) --- rtmp/data_loop.go | 8 ++++++-- rtmp/server.go | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/rtmp/data_loop.go b/rtmp/data_loop.go index 18c822e..50d4b0c 100644 --- a/rtmp/data_loop.go +++ b/rtmp/data_loop.go @@ -8,7 +8,8 @@ import ( ) func HandleDataLoop(chnk_wrp_ptr *ChunkWrapper) { - StreamCleanup(chnk_wrp_ptr.params.stream_key, 0) // remove any unwanted media files still left over + + StreamCleanup(chnk_wrp_ptr.params.stream_key, 0, nil) // remove any unwanted media files still left over file_writer, err := flv.NewFLVWriter(chnk_wrp_ptr.params.stream_key) // create a file writer (techincally a pipe to ffmpeg) defer file_writer.Close() if err != nil { @@ -37,9 +38,12 @@ func HandleDataLoop(chnk_wrp_ptr *ChunkWrapper) { } // find all files in given directory and delete, simple as -func StreamCleanup(stream_key string, delay time.Duration) { +func StreamCleanup(stream_key string, delay time.Duration, stream_live *bool) { time.Sleep(delay * time.Second) base_dir, _ := os.UserHomeDir() // why would this ever need error handling? if it throws a problem something went very wrong somewhere anyway + if stream_live != nil && *stream_live == true { + return + } stream_dir := base_dir + "/live/" + stream_key leftover_files, _ := filepath.Glob(stream_dir + "/*") diff --git a/rtmp/server.go b/rtmp/server.go index 3bf1c74..9d0813d 100644 --- a/rtmp/server.go +++ b/rtmp/server.go @@ -60,5 +60,5 @@ func handle_conn(conn net.Conn, stream_live *bool) { return } HandleDataLoop(chunk_wrapper) // no error handle since the connection ends either way - go StreamCleanup(chunk_wrapper.params.stream_key, 60) // remove any media files left 1 min after stream ends + go StreamCleanup(chunk_wrapper.params.stream_key, 10, stream_live) // remove any media files left 1 min after stream ends }