From 88fbce262f269093b361a4fe39b0b6870f809537 Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Thu, 21 May 2020 00:24:10 +0200 Subject: [PATCH] Implement sendFIR. --- client.go | 35 +++++++++++++++++++++++++++++++++++ conn.go | 2 ++ group.go | 1 + 3 files changed, 38 insertions(+) diff --git a/client.go b/client.go index 0551ddb..ff9a0cf 100644 --- a/client.go +++ b/client.go @@ -908,6 +908,41 @@ func sendPLI(pc *webrtc.PeerConnection, ssrc uint32) error { }) } +func (up *upConnection) sendFIR(track *upTrack, increment bool) error { + // we need to reliably increment the seqno, even if we are going + // to drop the packet due to rate limiting. + var seqno uint8 + if increment { + seqno = uint8(atomic.AddUint32(&track.firSeqno, 1) & 0xFF) + } else { + seqno = uint8(atomic.LoadUint32(&track.firSeqno) & 0xFF) + } + + if !track.hasRtcpFb("ccm", "fir") { + return ErrUnsupportedFeedback + } + last := atomic.LoadUint64(&track.lastFIR) + now := mono.Microseconds() + if now >= last && now-last < 200000 { + return ErrRateLimited + } + atomic.StoreUint64(&track.lastFIR, now) + return sendFIR(up.pc, track.track.SSRC(), seqno) +} + +func sendFIR(pc *webrtc.PeerConnection, ssrc uint32, seqno uint8) error { + return pc.WriteRTCP([]rtcp.Packet{ + &rtcp.FullIntraRequest{ + FIR: []rtcp.FIREntry{ + rtcp.FIREntry{ + SSRC: ssrc, + SequenceNumber: seqno, + }, + }, + }, + }) +} + func sendREMB(pc *webrtc.PeerConnection, ssrc uint32, bitrate uint64) error { return pc.WriteRTCP([]rtcp.Packet{ &rtcp.ReceiverEstimatedMaximumBitrate{ diff --git a/conn.go b/conn.go index 5edb185..01803f0 100644 --- a/conn.go +++ b/conn.go @@ -31,6 +31,8 @@ type upTrack struct { jitter *jitter.Estimator maxBitrate uint64 lastPLI uint64 + lastFIR uint64 + firSeqno uint32 lastSenderReport uint32 lastSenderReportTime uint32 diff --git a/group.go b/group.go index 6e150e6..b769a6b 100644 --- a/group.go +++ b/group.go @@ -112,6 +112,7 @@ func addGroup(name string, desc *groupDescription) (*group, error) { {"goog-remb", ""}, {"nack", ""}, {"nack", "pli"}, + {"ccm", "fir"}, }, "", ))