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

Rate-limit PLI.

This commit is contained in:
Juliusz Chroboczek 2020-04-28 20:15:24 +02:00
parent bfeeeb4bcd
commit e5dae16da1
2 changed files with 12 additions and 1 deletions

View file

@ -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},

View file

@ -24,6 +24,7 @@ type upTrack struct {
track *webrtc.Track
list *packetlist.List
maxBitrate uint64
lastPLI uint64
mu sync.Mutex
local []*downTrack