mirror of
https://github.com/livekit/livekit.git
synced 2026-05-22 17:05:50 +00:00
fix twcc panic on packet lost (#668)
This commit is contained in:
+12
-2
@@ -96,7 +96,9 @@ func (t *Responder) buildTransportCCPacket() rtcp.RawPacket {
|
||||
sort.Slice(t.extInfo, func(i, j int) bool {
|
||||
return t.extInfo[i].ExtTSN < t.extInfo[j].ExtTSN
|
||||
})
|
||||
tccPkts := make([]rtpExtInfo, 0, int(float64(len(t.extInfo))*1.2))
|
||||
maxTccPktsLen := int(float64(len(t.extInfo)) * 1.2)
|
||||
tccPkts := make([]rtpExtInfo, 0, maxTccPktsLen)
|
||||
var consumedExtInfo int
|
||||
for _, tccExtInfo := range t.extInfo {
|
||||
if tccExtInfo.ExtTSN < t.lastExtSN {
|
||||
continue
|
||||
@@ -108,8 +110,16 @@ func (t *Responder) buildTransportCCPacket() rtcp.RawPacket {
|
||||
}
|
||||
t.lastExtSN = tccExtInfo.ExtTSN
|
||||
tccPkts = append(tccPkts, tccExtInfo)
|
||||
consumedExtInfo++
|
||||
if len(tccPkts) >= maxTccPktsLen {
|
||||
break
|
||||
}
|
||||
}
|
||||
if consumedExtInfo == len(t.extInfo) {
|
||||
t.extInfo = t.extInfo[:0]
|
||||
} else {
|
||||
t.extInfo = t.extInfo[consumedExtInfo:]
|
||||
}
|
||||
t.extInfo = t.extInfo[:0]
|
||||
|
||||
firstRecv := false
|
||||
same := true
|
||||
|
||||
@@ -344,3 +344,15 @@ func BenchmarkBuildPacket(b *testing.B) {
|
||||
_ = twcc.buildTransportCCPacket()
|
||||
}
|
||||
}
|
||||
|
||||
func TestTccWithPacketLost(t *testing.T) {
|
||||
twcc := NewTransportWideCCResponder(123)
|
||||
var fbreceived int
|
||||
twcc.OnFeedback(func(p rtcp.RawPacket) { fbreceived++ })
|
||||
|
||||
for i := 0; i < 200; i++ {
|
||||
twcc.Push(10000+uint16(i*70), time.Now().UnixNano()+int64(i)*1e6, false)
|
||||
}
|
||||
|
||||
assert.Greater(t, fbreceived, 0)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user