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

Make NACK threshold depend on the average packet rate.

This commit is contained in:
Juliusz Chroboczek 2020-10-04 13:11:33 +02:00
parent 4a8e48d146
commit a233f10b0b

View file

@ -58,11 +58,35 @@ func readLoop(conn *rtpUpConnection, track *rtpUpTrack) {
}
first, index := track.cache.Store(
packet.SequenceNumber, packet.Timestamp, kf, buf[:bytes],
packet.SequenceNumber, packet.Timestamp,
kf, buf[:bytes],
)
_, rate := track.rate.Estimate()
delta := packet.SequenceNumber - first
if (delta & 0x8000) != 0 {
delta = 0
}
// send a NACK if a packet is late by 65ms or 2 packets,
// whichever is more
packets := rate / 16
if packets > 24 {
packets = 24
}
if packets < 2 {
packets = 2
}
// send NACKs for more recent packets, this makes better
// use of the NACK bitmap
unnacked := uint16(4)
if unnacked > uint16(packets) {
unnacked = uint16(packets)
}
if uint32(delta) > packets {
found, first, bitmap := track.cache.BitmapGet(
packet.SequenceNumber - unnacked,
)
if packet.SequenceNumber-first > 24 {
found, first, bitmap :=
track.cache.BitmapGet(packet.SequenceNumber - 4)
if found {
err := conn.sendNACK(track, first, bitmap)
if err != nil {
@ -71,7 +95,6 @@ func readLoop(conn *rtpUpConnection, track *rtpUpTrack) {
}
}
_, rate := track.rate.Estimate()
delay := uint32(rtptime.JiffiesPerSec / 1024)
if rate > 512 {
delay = rtptime.JiffiesPerSec / rate / 2