From 105331d50f8526f11dcf9b0f7332d7ca74227de7 Mon Sep 17 00:00:00 2001 From: Alexey Khit Date: Fri, 16 Sep 2022 17:22:48 +0300 Subject: [PATCH] Fix track async access --- pkg/streamer/track.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/streamer/track.go b/pkg/streamer/track.go index 2c2944c6..d3359d5a 100644 --- a/pkg/streamer/track.go +++ b/pkg/streamer/track.go @@ -32,6 +32,8 @@ func (t *Track) WriteRTP(p *rtp.Packet) error { } func (t *Track) Bind(w WriterFunc) *Track { + t.mx.Lock() + if t.Sink == nil { t.Sink = map[*Track]WriterFunc{} } @@ -39,9 +41,10 @@ func (t *Track) Bind(w WriterFunc) *Track { clone := &Track{ Codec: t.Codec, Direction: t.Direction, Sink: t.Sink, } - t.mx.Lock() t.Sink[clone] = w + t.mx.Unlock() + return clone }