Commit e5dae16d authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Rate-limit PLI.

parent bfeeeb4b
......@@ -511,7 +511,7 @@ func rtcpListener(g *group, conn *downConnection, track *downTrack, s *webrtc.RT
for _, p := range ps {
switch p := p.(type) {
case *rtcp.PictureLossIndication:
err := sendPLI(conn.remote.pc, p.MediaSSRC)
err := conn.remote.sendPLI(track.remote)
if err != nil {
log.Printf("sendPLI: %v", err)
}
......@@ -585,6 +585,16 @@ func updateUpBitrate(up *upConnection) {
}
}
func (up *upConnection) sendPLI(track *upTrack) error {
last := atomic.LoadUint64(&track.lastPLI)
now := msSinceEpoch()
if now >= last && now - last < 200 {
return nil
}
atomic.StoreUint64(&track.lastPLI, now)
return sendPLI(up.pc, track.track.SSRC())
}
func sendPLI(pc *webrtc.PeerConnection, ssrc uint32) error {
return pc.WriteRTCP([]rtcp.Packet{
&rtcp.PictureLossIndication{MediaSSRC: ssrc},
......
......@@ -24,6 +24,7 @@ type upTrack struct {
track *webrtc.Track
list *packetlist.List
maxBitrate uint64
lastPLI uint64
mu sync.Mutex
local []*downTrack
......
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