From 116319f8766664784baf68e867db1cc8bee3d9ac Mon Sep 17 00:00:00 2001 From: Alexey Khit Date: Mon, 17 Apr 2023 14:17:45 +0300 Subject: [PATCH] Restore mutex for MP4 --- cmd/mp4/mp4.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/mp4/mp4.go b/cmd/mp4/mp4.go index e7762f63..2e47d770 100644 --- a/cmd/mp4/mp4.go +++ b/cmd/mp4/mp4.go @@ -4,6 +4,7 @@ import ( "net/http" "strconv" "strings" + "sync" "time" "github.com/AlexxIT/go2rtc/cmd/api" @@ -108,9 +109,14 @@ func handlerMP4(w http.ResponseWriter, r *http.Request) { Medias: core.ParseQuery(r.URL.Query()), } + var mu sync.Mutex cons.Listen(func(msg any) { if data, ok := msg.([]byte); ok { - if _, err := w.Write(data); err != nil && exit != nil { + mu.Lock() + _, err := w.Write(data) + mu.Unlock() + + if err != nil && exit != nil { select { case exit <- err: default: