fix sender report batching to not exceed MTU

This commit is contained in:
David Zhao
2021-06-03 15:46:41 -07:00
parent 855217bd1c
commit 0416299e02
+22 -7
View File
@@ -28,7 +28,7 @@ const (
lossyDataChannel = "_lossy" lossyDataChannel = "_lossy"
reliableDataChannel = "_reliable" reliableDataChannel = "_reliable"
privateDataChannel = "_private" privateDataChannel = "_private"
sdBatchSize = 15 sdBatchSize = 20
) )
type ParticipantParams struct { type ParticipantParams struct {
@@ -863,7 +863,7 @@ func (p *ParticipantImpl) downTracksRTCPWorker() {
continue continue
} }
var pkts []rtcp.Packet var srs []rtcp.Packet
var sd []rtcp.SourceDescriptionChunk var sd []rtcp.SourceDescriptionChunk
p.lock.RLock() p.lock.RLock()
for _, tracks := range p.subscribedTracks { for _, tracks := range p.subscribedTracks {
@@ -873,19 +873,31 @@ func (p *ParticipantImpl) downTracksRTCPWorker() {
if sr == nil || chunks == nil { if sr == nil || chunks == nil {
continue continue
} }
pkts = append(pkts, sr) srs = append(srs, sr)
sd = append(sd, chunks...) sd = append(sd, chunks...)
} }
} }
p.lock.RUnlock() p.lock.RUnlock()
// now send in batches of sdBatchSize // now send in batches of sdBatchSize
// first batch will contain the sender reports too
var batch []rtcp.SourceDescriptionChunk var batch []rtcp.SourceDescriptionChunk
for len(sd) > 0 { var pkts []rtcp.Packet
batchSize := 0
for len(sd) > 0 || len(srs) > 0 {
numSRs := len(srs)
if numSRs > 0 {
if numSRs > sdBatchSize {
numSRs = sdBatchSize
}
pkts = append(pkts, srs[:numSRs]...)
srs = srs[numSRs:]
}
size := len(sd) size := len(sd)
if size > sdBatchSize { spaceRemain := sdBatchSize - batchSize
size = sdBatchSize if spaceRemain > 0 && size > 0 {
if size > spaceRemain {
size = spaceRemain
} }
batch = sd[:size] batch = sd[:size]
sd = sd[size:] sd = sd[size:]
@@ -897,7 +909,10 @@ func (p *ParticipantImpl) downTracksRTCPWorker() {
logger.Errorw("could not send downtrack reports", err, logger.Errorw("could not send downtrack reports", err,
"participant", p.Identity()) "participant", p.Identity())
} }
}
pkts = pkts[:0] pkts = pkts[:0]
batchSize = 0
} }
} }
} }