Skip to content

Commit c770c72

Browse files
astrozamengelbart
authored andcommitted
BuildReport() was exceeding the maxSize limit
1 parent 28775a6 commit c770c72

File tree

2 files changed

+39
-18
lines changed

2 files changed

+39
-18
lines changed

pkg/rfc8888/recorder.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,9 @@ func (r *Recorder) BuildReport(now time.Time, maxSize int) *rtcp.CCFeedbackRepor
4949
}
5050

5151
maxReportBlocks := (maxSize - 12 - (8 * len(r.streams))) / 2
52-
var maxReportBlocksPerStream int
53-
if len(r.streams) > 1 {
54-
maxReportBlocksPerStream = maxReportBlocks / (len(r.streams) - 1)
55-
} else {
56-
maxReportBlocksPerStream = maxReportBlocks
57-
}
52+
maxReportBlocksPerStream := maxReportBlocks / len(r.streams)
5853

59-
for i, log := range r.streams {
60-
if len(r.streams) > 1 && int(i) == len(r.streams)-1 {
61-
maxReportBlocksPerStream = maxReportBlocks % len(r.streams)
62-
}
54+
for _, log := range r.streams {
6355
block := log.metricsAfter(now, int64(maxReportBlocksPerStream))
6456
report.ReportBlocks = append(report.ReportBlocks, block)
6557
}

pkg/rfc8888/recorder_test.go

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package rfc8888
55

66
import (
7+
"math/rand"
78
"testing"
89
"time"
910

@@ -142,21 +143,49 @@ func TestRecorder(t *testing.T) {
142143
}, report.ReportBlocks[0])
143144
})
144145

145-
t.Run("MaxreportsPerStream", func(t *testing.T) {
146+
t.Run("MaxreportsPerStream 3 streams", func(t *testing.T) {
146147
recorder := NewRecorder()
147148
now := time.Time{}
149+
maxSize := 1200
148150

151+
streams := 3
152+
packets := 1000
153+
// Add 1000 packets on 3 different streams
154+
for i := 0; i < streams; i++ {
155+
ssrc := rand.Uint32() //nolint:gosec
156+
for j := 0; j < packets; j++ {
157+
recorder.AddPacket(now, ssrc, uint16(j), 0) //nolint:gosec // G115
158+
}
159+
}
160+
reports := recorder.BuildReport(time.Time{}, maxSize)
161+
162+
blocks := 0
163+
for i := 0; i < streams; i++ {
164+
blocks += len(reports.ReportBlocks[i].MetricBlocks)
165+
}
166+
assert.Less(t, blocks*2, maxSize)
167+
})
168+
169+
t.Run("MaxreportsPerStream 10 streams", func(t *testing.T) {
170+
recorder := NewRecorder()
171+
now := time.Time{}
172+
maxSize := 1300
173+
174+
streams := 10
175+
packets := 1000
149176
// Add 1000 packets on 10 different streams
150-
for i := 0; i < 10; i++ {
151-
for j := 0; j < 100; j++ {
152-
recorder.AddPacket(now, uint32(i), uint16(j), 0) //nolint:gosec // G115
177+
for i := 0; i < streams; i++ {
178+
ssrc := rand.Uint32() //nolint:gosec
179+
for j := 0; j < packets; j++ {
180+
recorder.AddPacket(now, ssrc, uint16(j), 0) //nolint:gosec // G115
153181
}
154182
}
155-
reports := recorder.BuildReport(time.Time{}, 1380)
183+
reports := recorder.BuildReport(time.Time{}, maxSize)
156184

157-
for i := 0; i < 10; i++ {
158-
assert.Greater(t, 72, len(reports.ReportBlocks[i].MetricBlocks))
159-
assert.Less(t, 3, len(reports.ReportBlocks[i].MetricBlocks))
185+
blocks := 0
186+
for i := 0; i < streams; i++ {
187+
blocks += len(reports.ReportBlocks[i].MetricBlocks)
160188
}
189+
assert.Less(t, blocks*2, maxSize)
161190
})
162191
}

0 commit comments

Comments
 (0)