From a7aa9e23d06a17214b692bdc27b5b92b8f629bc2 Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Sat, 26 Feb 2022 19:48:01 +0100 Subject: [PATCH] add mutex around SPS and PPS of TrackH264 --- track_h264.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/track_h264.go b/track_h264.go index 194475da..70e7475a 100644 --- a/track_h264.go +++ b/track_h264.go @@ -6,6 +6,7 @@ import ( "fmt" "strconv" "strings" + "sync" psdp "github.com/pion/sdp/v3" @@ -65,6 +66,7 @@ type TrackH264 struct { sps []byte pps []byte extradata []byte + mutex sync.RWMutex } // NewTrackH264 allocates a TrackH264. @@ -127,11 +129,15 @@ func (t *TrackH264) url(contentBase *base.URL) (*base.URL, error) { // SPS returns the track SPS. func (t *TrackH264) SPS() []byte { + t.mutex.RLock() + defer t.mutex.RUnlock() return t.sps } // PPS returns the track PPS. func (t *TrackH264) PPS() []byte { + t.mutex.RLock() + defer t.mutex.RUnlock() return t.pps } @@ -142,16 +148,23 @@ func (t *TrackH264) ExtraData() []byte { // SetSPS sets the track SPS. func (t *TrackH264) SetSPS(v []byte) { + t.mutex.Lock() + defer t.mutex.Unlock() t.sps = v } // SetPPS sets the track PPS. func (t *TrackH264) SetPPS(v []byte) { + t.mutex.Lock() + defer t.mutex.Unlock() t.pps = v } // MediaDescription returns the media description in SDP format. func (t *TrackH264) MediaDescription() *psdp.MediaDescription { + t.mutex.RLock() + defer t.mutex.RUnlock() + typ := strconv.FormatInt(int64(t.payloadType), 10) fmtp := typ + " packetization-mode=1"