auto-clean stream directory at start of new stream and after 1m at end of stream, holy shit it just works
This commit is contained in:
parent
f80e86fcf6
commit
5941184ada
2 changed files with 16 additions and 0 deletions
|
@ -3,9 +3,12 @@ package rtmp
|
|||
import (
|
||||
"stream_server/rtmp/flv"
|
||||
"os"
|
||||
"time"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
func HandleDataLoop(chnk_wrp_ptr *ChunkWrapper) {
|
||||
StreamCleanup(chnk_wrp_ptr.params.stream_key, 0)
|
||||
base_dir, _ := os.UserHomeDir()
|
||||
file_writer, err := flv.NewFLVWriter(base_dir + "/live/" + chnk_wrp_ptr.params.stream_key + "/")
|
||||
defer file_writer.Close()
|
||||
|
@ -32,3 +35,15 @@ func HandleDataLoop(chnk_wrp_ptr *ChunkWrapper) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func StreamCleanup(stream_key string, delay time.Duration) {
|
||||
time.Sleep(delay * time.Second)
|
||||
base_dir, _ := os.UserHomeDir()
|
||||
stream_dir := base_dir + "/live/" + stream_key
|
||||
|
||||
leftover_files, _ := filepath.Glob(stream_dir + "/*")
|
||||
for _, file := range leftover_files {
|
||||
os.Remove(file)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -53,5 +53,6 @@ func handle_conn(conn net.Conn, stream_live *bool) {
|
|||
return
|
||||
}
|
||||
HandleDataLoop(chunk_wrapper)
|
||||
go StreamCleanup(chunk_wrapper.params.stream_key, 60)
|
||||
*stream_live = false
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue