new track system

This commit is contained in:
aler9
2022-01-28 17:42:20 +01:00
committed by Alessandro Ros
parent cd0db96a5d
commit 6d5bf0c1bb
31 changed files with 1523 additions and 1432 deletions

View File

@@ -34,13 +34,15 @@ type ServerStream struct {
// NewServerStream allocates a ServerStream.
func NewServerStream(tracks Tracks) *ServerStream {
tracks = tracks.clone()
tracks.setControls()
st := &ServerStream{
tracks: tracks,
readersUnicast: make(map[*ServerSession]struct{}),
readers: make(map[*ServerSession]struct{}),
}
st.tracks = cloneAndClearTracks(tracks)
st.trackInfos = make([]*trackInfo, len(tracks))
for i := range st.trackInfos {
st.trackInfos[i] = &trackInfo{}
@@ -90,14 +92,13 @@ func (st *ServerStream) ssrc(trackID int) uint32 {
func (st *ServerStream) timestamp(trackID int) uint32 {
lastTimeRTP := atomic.LoadUint32(&st.trackInfos[trackID].lastTimeRTP)
lastTimeNTP := atomic.LoadInt64(&st.trackInfos[trackID].lastTimeNTP)
clockRate, _ := st.tracks[trackID].ClockRate()
if lastTimeRTP == 0 || lastTimeNTP == 0 {
return 0
}
return uint32(uint64(lastTimeRTP) +
uint64(time.Since(time.Unix(lastTimeNTP, 0)).Seconds()*float64(clockRate)))
uint64(time.Since(time.Unix(lastTimeNTP, 0)).Seconds()*float64(st.tracks[trackID].ClockRate())))
}
func (st *ServerStream) lastSequenceNumber(trackID int) uint16 {