1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-10 02:35:58 +01:00

Tweak SR sending policy.

Don't send SRs for tracks for which we have no time offset yet.
Send an unscheduled SR when we get our first time offset.
This commit is contained in:
Juliusz Chroboczek 2020-06-04 19:12:52 +02:00
parent ce7f3670bc
commit 8ba50bd2ca

View file

@ -547,6 +547,7 @@ func writeLoop(conn *upConnection, track *upTrack, ch <-chan packetIndex) {
func rtcpUpListener(conn *upConnection, track *upTrack, r *webrtc.RTPReceiver) {
for {
firstSR := false
ps, err := r.ReadRTCP()
if err != nil {
if err != io.EOF {
@ -555,17 +556,37 @@ func rtcpUpListener(conn *upConnection, track *upTrack, r *webrtc.RTPReceiver) {
return
}
now := rtptime.Jiffies()
for _, p := range ps {
switch p := p.(type) {
case *rtcp.SenderReport:
track.mu.Lock()
track.srTime = rtptime.Jiffies()
if track.srTime == 0 {
firstSR = true
}
track.srTime = now
track.srNTPTime = p.NTPTime
track.srRTPTime = p.RTPTime
track.mu.Unlock()
case *rtcp.SourceDescription:
}
}
if(firstSR) {
// this is the first SR we got for at least one track,
// quickly propagate the time offsets downstream
local := conn.getLocal()
for _, l := range local {
l, ok := l.(*rtpDownConnection)
if ok {
err := sendSR(l)
if err != nil {
log.Printf("sendSR: %v", err)
}
}
}
}
}
}
@ -638,11 +659,18 @@ func sendSR(conn *rtpDownConnection) error {
for _, t := range conn.tracks {
clockrate := t.track.Codec().ClockRate
remote := t.remote
remote.mu.Lock()
lastTime := remote.srTime
srNTPTime := remote.srNTPTime
srRTPTime := remote.srRTPTime
remote.mu.Unlock()
if lastTime == 0 {
// we never got a remote SR, skip this track
continue
}
nowRTP := srRTPTime
if srNTPTime != 0 {
srTime := rtptime.NTPToTime(srNTPTime)
@ -666,6 +694,10 @@ func sendSR(conn *rtpDownConnection) error {
atomic.StoreUint64(&t.srNTPTime, nowNTP)
}
if len(packets) == 0 {
return nil
}
return conn.pc.WriteRTCP(packets)
}