mirror of
https://github.com/livekit/livekit.git
synced 2026-11-23 00:19:05 +00:00
Report loss before repair only to FlexFEC publishers
Counting repaired packets as lost in receiver reports applied to every publisher, so any publisher whose loss RTX repaired started to see that loss and its bandwidth estimate could back off sooner. Only FlexFEC protection needs loss before repair to choose its rate. Count repairs only for streams that negotiated flexfec-03, which requires FlexFEC to be enabled on the server. Other publishers keep receiving loss after repair, as before.
This commit is contained in:
1 parent
d0d88289fb
commit
e0e6e25acb
3 files changed
+62
-2
No files matched your search
@@ -866,8 +866,11 @@ func (b *BufferBase) HandleIncomingPacketLocked(
|
||||
return 0, fmt.Errorf("unhandled reason: %s", flowState.UnhandledReason.String())
|
||||
}
|
||||
|
||||
if isRTX && flowState.IsLossFilled {
|
||||
// RTX retransmissions and FEC recoveries both arrive as repairs
|
||||
if isRTX && flowState.IsLossFilled && b.fecPayloadType != 0 {
|
||||
// RTX retransmissions and FEC recoveries both arrive as repairs. Report
|
||||
// them as lost only to publishers that negotiated FlexFEC, whose
|
||||
// protection follows reported loss; other publishers keep seeing loss
|
||||
// after repair, as before.
|
||||
b.rtpStats.UpdateRepaired()
|
||||
}
|
||||
|
||||
|
||||
@@ -812,3 +812,59 @@ func TestBufferBaseRTXRepairedHistory(t *testing.T) {
|
||||
buff.restartStreamLocked("test", false)
|
||||
require.False(t, buff.isRTXRepairedLocked(repairedSN))
|
||||
}
|
||||
|
||||
func TestBufferReportsRepairedAsLostOnlyWithFlexFEC(t *testing.T) {
|
||||
const (
|
||||
rtxSSRC = uint32(0x33333333)
|
||||
rtxPT = uint8(97)
|
||||
)
|
||||
rtxCodec := webrtc.RTPCodecParameters{
|
||||
RTPCodecCapability: webrtc.RTPCodecCapability{
|
||||
MimeType: webrtc.MimeTypeRTX,
|
||||
ClockRate: 90000,
|
||||
SDPFmtpLine: "apt=96",
|
||||
},
|
||||
PayloadType: webrtc.PayloadType(rtxPT),
|
||||
}
|
||||
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
codecs []webrtc.RTPCodecParameters
|
||||
totalLost uint32
|
||||
}{
|
||||
{"without FlexFEC", []webrtc.RTPCodecParameters{vp8Codec, rtxCodec}, 0},
|
||||
{"with FlexFEC", []webrtc.RTPCodecParameters{vp8Codec, rtxCodec, flexFECCodec}, 1},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
factory := NewFactoryOfBufferFactory(500, 200).CreateBufferFactory()
|
||||
primary := factory.GetOrNew(packetio.RTPBufferPacket, fecTestMediaSSRC).(*Buffer)
|
||||
rtxBuff := factory.GetOrNew(packetio.RTPBufferPacket, rtxSSRC).(*Buffer)
|
||||
factory.SetRTXPair(rtxSSRC, fecTestMediaSSRC, "")
|
||||
|
||||
primary.codecType = webrtc.RTPCodecTypeVideo
|
||||
require.NoError(t, primary.Bind(webrtc.RTPParameters{Codecs: tc.codecs}, vp8Codec.RTPCodecCapability, 0))
|
||||
|
||||
media := rtptest.GenerateVP8Packets(100, 10, uint8(vp8Codec.PayloadType), fecTestMediaSSRC)
|
||||
const lostIdx = 4
|
||||
for i := range media {
|
||||
if i != lostIdx {
|
||||
writePacket(t, primary, &media[i])
|
||||
}
|
||||
}
|
||||
|
||||
retransmitted := media[lostIdx].Clone()
|
||||
retransmitted.SSRC = rtxSSRC
|
||||
retransmitted.PayloadType = rtxPT
|
||||
retransmitted.SequenceNumber = 500
|
||||
retransmitted.Payload = binary.BigEndian.AppendUint16(nil, media[lostIdx].SequenceNumber)
|
||||
retransmitted.Payload = append(retransmitted.Payload, media[lostIdx].Payload...)
|
||||
writePacket(t, rtxBuff, retransmitted)
|
||||
|
||||
primary.Lock()
|
||||
rr := primary.GetRtcpReceptionReportLocked(0)
|
||||
primary.Unlock()
|
||||
require.NotNil(t, rr)
|
||||
require.Equal(t, tc.totalLost, rr.TotalLost)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -838,6 +838,7 @@ func (r *RTPStatsReceiver) LastSenderReportTime() time.Time {
|
||||
|
||||
// UpdateRepaired records a lost packet that was filled by a repair, an RTX
|
||||
// retransmission or a FEC recovery. Receiver reports keep counting it as lost.
|
||||
// Callers decide which streams report loss before repair.
|
||||
func (r *RTPStatsReceiver) UpdateRepaired() {
|
||||
r.lock.Lock()
|
||||
defer r.lock.Unlock()
|
||||
|
||||
Reference in new issue
Block a user