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
+32 -17
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,31 +873,46 @@ 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
size := len(sd) batchSize := 0
if size > sdBatchSize { for len(sd) > 0 || len(srs) > 0 {
size = sdBatchSize numSRs := len(srs)
} if numSRs > 0 {
batch = sd[:size] if numSRs > sdBatchSize {
sd = sd[size:] numSRs = sdBatchSize
pkts = append(pkts, &rtcp.SourceDescription{Chunks: batch})
if err := p.subscriber.pc.WriteRTCP(pkts); err != nil {
if err == io.EOF || err == io.ErrClosedPipe {
return
} }
logger.Errorw("could not send downtrack reports", err, pkts = append(pkts, srs[:numSRs]...)
"participant", p.Identity()) srs = srs[numSRs:]
} }
size := len(sd)
spaceRemain := sdBatchSize - batchSize
if spaceRemain > 0 && size > 0 {
if size > spaceRemain {
size = spaceRemain
}
batch = sd[:size]
sd = sd[size:]
pkts = append(pkts, &rtcp.SourceDescription{Chunks: batch})
if err := p.subscriber.pc.WriteRTCP(pkts); err != nil {
if err == io.EOF || err == io.ErrClosedPipe {
return
}
logger.Errorw("could not send downtrack reports", err,
"participant", p.Identity())
}
}
pkts = pkts[:0] pkts = pkts[:0]
batchSize = 0
} }
} }
} }