From 0e1f3cafea460aef9245a4c437662188ebc3f95b Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Thu, 21 May 2020 13:17:52 +0200 Subject: [PATCH] Drop until end of frame when writer is congested. --- client.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/client.go b/client.go index deb6473..dcb4a9f 100644 --- a/client.go +++ b/client.go @@ -388,12 +388,14 @@ type packetIndex struct { } func readLoop(conn *upConnection, track *upTrack) { + isvideo := track.track.Kind() == webrtc.RTPCodecTypeVideo ch := make(chan packetIndex, 32) defer close(ch) go writeLoop(conn, track, ch) buf := make([]byte, packetcache.BufSize) var packet rtp.Packet + drop := 0 for { bytes, err := track.track.Read(buf) if err != nil { @@ -424,11 +426,26 @@ func readLoop(conn *upConnection, track *upTrack) { } } + if drop > 0 { + if packet.Marker { + // last packet in frame + drop = 0 + } else { + drop-- + } + continue + } + select { case ch <- packetIndex{packet.SequenceNumber, index}: default: - // The writer is congested. Drop the packet, and - // leave it to NACK recovery if possible. + if isvideo { + // the writer is congested. Drop until + // the end of the frame. + if isvideo && !packet.Marker { + drop = 7 + } + } } } }