mirror of
https://github.com/aler9/gortsplib
synced 2025-11-02 03:22:58 +08:00
add mutex around SPS and PPS of TrackH264
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
|
||||||
psdp "github.com/pion/sdp/v3"
|
psdp "github.com/pion/sdp/v3"
|
||||||
|
|
||||||
@@ -65,6 +66,7 @@ type TrackH264 struct {
|
|||||||
sps []byte
|
sps []byte
|
||||||
pps []byte
|
pps []byte
|
||||||
extradata []byte
|
extradata []byte
|
||||||
|
mutex sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTrackH264 allocates a TrackH264.
|
// NewTrackH264 allocates a TrackH264.
|
||||||
@@ -127,11 +129,15 @@ func (t *TrackH264) url(contentBase *base.URL) (*base.URL, error) {
|
|||||||
|
|
||||||
// SPS returns the track SPS.
|
// SPS returns the track SPS.
|
||||||
func (t *TrackH264) SPS() []byte {
|
func (t *TrackH264) SPS() []byte {
|
||||||
|
t.mutex.RLock()
|
||||||
|
defer t.mutex.RUnlock()
|
||||||
return t.sps
|
return t.sps
|
||||||
}
|
}
|
||||||
|
|
||||||
// PPS returns the track PPS.
|
// PPS returns the track PPS.
|
||||||
func (t *TrackH264) PPS() []byte {
|
func (t *TrackH264) PPS() []byte {
|
||||||
|
t.mutex.RLock()
|
||||||
|
defer t.mutex.RUnlock()
|
||||||
return t.pps
|
return t.pps
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,16 +148,23 @@ func (t *TrackH264) ExtraData() []byte {
|
|||||||
|
|
||||||
// SetSPS sets the track SPS.
|
// SetSPS sets the track SPS.
|
||||||
func (t *TrackH264) SetSPS(v []byte) {
|
func (t *TrackH264) SetSPS(v []byte) {
|
||||||
|
t.mutex.Lock()
|
||||||
|
defer t.mutex.Unlock()
|
||||||
t.sps = v
|
t.sps = v
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetPPS sets the track PPS.
|
// SetPPS sets the track PPS.
|
||||||
func (t *TrackH264) SetPPS(v []byte) {
|
func (t *TrackH264) SetPPS(v []byte) {
|
||||||
|
t.mutex.Lock()
|
||||||
|
defer t.mutex.Unlock()
|
||||||
t.pps = v
|
t.pps = v
|
||||||
}
|
}
|
||||||
|
|
||||||
// MediaDescription returns the media description in SDP format.
|
// MediaDescription returns the media description in SDP format.
|
||||||
func (t *TrackH264) MediaDescription() *psdp.MediaDescription {
|
func (t *TrackH264) MediaDescription() *psdp.MediaDescription {
|
||||||
|
t.mutex.RLock()
|
||||||
|
defer t.mutex.RUnlock()
|
||||||
|
|
||||||
typ := strconv.FormatInt(int64(t.payloadType), 10)
|
typ := strconv.FormatInt(int64(t.payloadType), 10)
|
||||||
|
|
||||||
fmtp := typ + " packetization-mode=1"
|
fmtp := typ + " packetization-mode=1"
|
||||||
|
|||||||
Reference in New Issue
Block a user