Commit 8ba50bd2 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

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.
parent ce7f3670
...@@ -547,6 +547,7 @@ func writeLoop(conn *upConnection, track *upTrack, ch <-chan packetIndex) { ...@@ -547,6 +547,7 @@ func writeLoop(conn *upConnection, track *upTrack, ch <-chan packetIndex) {
func rtcpUpListener(conn *upConnection, track *upTrack, r *webrtc.RTPReceiver) { func rtcpUpListener(conn *upConnection, track *upTrack, r *webrtc.RTPReceiver) {
for { for {
firstSR := false
ps, err := r.ReadRTCP() ps, err := r.ReadRTCP()
if err != nil { if err != nil {
if err != io.EOF { if err != io.EOF {
...@@ -555,17 +556,37 @@ func rtcpUpListener(conn *upConnection, track *upTrack, r *webrtc.RTPReceiver) { ...@@ -555,17 +556,37 @@ func rtcpUpListener(conn *upConnection, track *upTrack, r *webrtc.RTPReceiver) {
return return
} }
now := rtptime.Jiffies()
for _, p := range ps { for _, p := range ps {
switch p := p.(type) { switch p := p.(type) {
case *rtcp.SenderReport: case *rtcp.SenderReport:
track.mu.Lock() track.mu.Lock()
track.srTime = rtptime.Jiffies() if track.srTime == 0 {
firstSR = true
}
track.srTime = now
track.srNTPTime = p.NTPTime track.srNTPTime = p.NTPTime
track.srRTPTime = p.RTPTime track.srRTPTime = p.RTPTime
track.mu.Unlock() track.mu.Unlock()
case *rtcp.SourceDescription: 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 { ...@@ -638,11 +659,18 @@ func sendSR(conn *rtpDownConnection) error {
for _, t := range conn.tracks { for _, t := range conn.tracks {
clockrate := t.track.Codec().ClockRate clockrate := t.track.Codec().ClockRate
remote := t.remote remote := t.remote
remote.mu.Lock() remote.mu.Lock()
lastTime := remote.srTime
srNTPTime := remote.srNTPTime srNTPTime := remote.srNTPTime
srRTPTime := remote.srRTPTime srRTPTime := remote.srRTPTime
remote.mu.Unlock() remote.mu.Unlock()
if lastTime == 0 {
// we never got a remote SR, skip this track
continue
}
nowRTP := srRTPTime nowRTP := srRTPTime
if srNTPTime != 0 { if srNTPTime != 0 {
srTime := rtptime.NTPToTime(srNTPTime) srTime := rtptime.NTPToTime(srNTPTime)
...@@ -666,6 +694,10 @@ func sendSR(conn *rtpDownConnection) error { ...@@ -666,6 +694,10 @@ func sendSR(conn *rtpDownConnection) error {
atomic.StoreUint64(&t.srNTPTime, nowNTP) atomic.StoreUint64(&t.srNTPTime, nowNTP)
} }
if len(packets) == 0 {
return nil
}
return conn.pc.WriteRTCP(packets) return conn.pc.WriteRTCP(packets)
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment