diff --git a/client.go b/client.go index c5a5331..d70c16b 100644 --- a/client.go +++ b/client.go @@ -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}, diff --git a/group.go b/group.go index 89eb56e..378f587 100644 --- a/group.go +++ b/group.go @@ -24,6 +24,7 @@ type upTrack struct { track *webrtc.Track list *packetlist.List maxBitrate uint64 + lastPLI uint64 mu sync.Mutex local []*downTrack