change cleanup to check for active stream (prevents segment wipe on reconnect)

This commit is contained in:
Muaz Ahmad 2023-08-24 12:51:12 +05:00
parent 82a426ef49
commit 33fc16f38c
2 changed files with 7 additions and 3 deletions

View file

@ -8,7 +8,8 @@ import (
) )
func HandleDataLoop(chnk_wrp_ptr *ChunkWrapper) { 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) file_writer, err := flv.NewFLVWriter(chnk_wrp_ptr.params.stream_key) // create a file writer (techincally a pipe to ffmpeg)
defer file_writer.Close() defer file_writer.Close()
if err != nil { if err != nil {
@ -37,9 +38,12 @@ func HandleDataLoop(chnk_wrp_ptr *ChunkWrapper) {
} }
// find all files in given directory and delete, simple as // 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) 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 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 stream_dir := base_dir + "/live/" + stream_key
leftover_files, _ := filepath.Glob(stream_dir + "/*") leftover_files, _ := filepath.Glob(stream_dir + "/*")

View file

@ -60,5 +60,5 @@ func handle_conn(conn net.Conn, stream_live *bool) {
return return
} }
HandleDataLoop(chunk_wrapper) // no error handle since the connection ends either way 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
} }