From 67a821ea75b0e5b6d2fc6947d06230c2cfe8f8f2 Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Sat, 3 Oct 2020 15:53:16 +0200 Subject: [PATCH] Increase minimum size of packet cache. Now that we cache keyframes, it is worth keeping some history even when latency is low. --- rtpconn/rtpconn.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/rtpconn/rtpconn.go b/rtpconn/rtpconn.go index f9c9784..3b32fd2 100644 --- a/rtpconn/rtpconn.go +++ b/rtpconn/rtpconn.go @@ -418,7 +418,7 @@ func newUpConn(c group.Client, id string) (*rtpUpConnection, error) { track := &rtpUpTrack{ track: remote, label: label, - cache: packetcache.New(32), + cache: packetcache.New(minPacketCache(remote)), rate: estimator.New(time.Second), jitter: jitter.New(remote.Codec().ClockRate), localCh: make(chan localTrackAction, 2), @@ -972,6 +972,13 @@ func handleReport(track *rtpDownTrack, report rtcp.ReceptionReport, jiffies uint } } +func minPacketCache(track *webrtc.Track) int { + if track.Kind() == webrtc.RTPCodecTypeVideo { + return 128 + } + return 24 +} + func updateUpTrack(track *rtpUpTrack) { now := rtptime.Jiffies() @@ -993,11 +1000,12 @@ func updateUpTrack(track *rtpUpTrack) { } _, r := track.rate.Estimate() packets := int((uint64(r) * maxrto * 4) / rtptime.JiffiesPerSec) - if packets < 32 { - packets = 32 + min := minPacketCache(track.track) + if packets < min { + packets = min } - if packets > 256 { - packets = 256 + if packets > 1024 { + packets = 1024 } track.cache.ResizeCond(packets) }