Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ linters:
- maintidx # maintidx measures the maintainability index of each function.
- makezero # Finds slice declarations with non-zero initial length
- misspell # Finds commonly misspelled English words in comments
- modernize # Replace and suggests simplifications to code
- nakedret # Finds naked returns in functions greater than a specified function length
- nestif # Reports deeply nested if statements
- nilerr # Finds the code that returns nil even if it checks that the error is not nil.
Expand Down
2 changes: 1 addition & 1 deletion errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestMultiError(t *testing.T) {
errIs, ok := errs.(multiError) //nolint
assert.True(t, ok, "FlattenErrs returns non-multiError")

for i := 0; i < 3; i++ {
for i := range 3 {
assert.True(t, errIs.Is(rawErrs[i]), "Should contain error %d", i)
}
assert.False(t, errIs.Is(rawErrs[3]), "Should not contain error %d", 3)
Expand Down
16 changes: 6 additions & 10 deletions internal/cc/feedback_adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,6 @@ func TestUnpackRunLengthChunk(t *testing.T) {

//nolint:dupl
for i, tc := range cases {
i := i
tc := tc
t.Run(fmt.Sprintf("%v", i), func(t *testing.T) {
fa := NewFeedbackAdapter()

Expand Down Expand Up @@ -397,8 +395,6 @@ func TestUnpackStatusVectorChunk(t *testing.T) {

//nolint:dupl
for i, tc := range cases {
i := i
tc := tc
t.Run(fmt.Sprintf("%v", i), func(t *testing.T) {
fa := NewFeedbackAdapter()

Expand Down Expand Up @@ -455,7 +451,7 @@ func TestFeedbackAdapterTWCC(t *testing.T) {
t0 := time.Time{}
adapter := NewFeedbackAdapter()
headers := []rtp.Header{}
for i := uint16(0); i < 22; i++ {
for i := range uint16(22) {
pkt := getPacketWithTransportCCExt(t, i)
headers = append(headers, pkt.Header)
assert.NoError(
Expand Down Expand Up @@ -694,7 +690,7 @@ func TestFeedbackAdapterTWCC(t *testing.T) {
t0 := time.Time{}
adapter := NewFeedbackAdapter()
headers := []rtp.Header{}
for i := uint16(0); i < 8; i++ {
for i := range uint16(8) {
pkt := getPacketWithTransportCCExt(t, i)
headers = append(headers, pkt.Header)
assert.NoError(
Expand Down Expand Up @@ -744,7 +740,7 @@ func TestFeedbackAdapterTWCC(t *testing.T) {
})
assert.NoError(t, err)
assert.Len(t, results, 7)
for i := uint16(0); i < 3; i++ {
for i := range uint16(3) {
assert.Contains(t, results, Acknowledgment{
SequenceNumber: i,
Size: headers[i].MarshalSize() + 1200,
Expand All @@ -765,7 +761,7 @@ func TestFeedbackAdapterTWCC(t *testing.T) {
t.Run("runLengthChunk", func(t *testing.T) {
adapter := NewFeedbackAdapter()
t0 := time.Time{}
for i := uint16(0); i < 20; i++ {
for i := range uint16(20) {
pkt := getPacketWithTransportCCExt(t, i)
assert.NoError(
t,
Expand Down Expand Up @@ -809,7 +805,7 @@ func TestFeedbackAdapterTWCC(t *testing.T) {
t.Run("statusVectorChunk", func(t *testing.T) {
adapter := NewFeedbackAdapter()
t0 := time.Time{}
for i := uint16(0); i < 20; i++ {
for i := range uint16(20) {
pkt := getPacketWithTransportCCExt(t, i)
assert.NoError(
t,
Expand Down Expand Up @@ -869,7 +865,7 @@ func TestFeedbackAdapterTWCC(t *testing.T) {
adapter := NewFeedbackAdapter()

t0 := time.Time{}
for i := uint16(0); i < 20; i++ {
for i := range uint16(20) {
pkt := getPacketWithTransportCCExt(t, i)
assert.NoError(
t,
Expand Down
2 changes: 1 addition & 1 deletion internal/rtpbuffer/rtpbuffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type RTPBuffer struct {
func NewRTPBuffer(size uint16) (*RTPBuffer, error) {
allowedSizes := make([]uint16, 0)
correctSize := false
for i := 0; i < 16; i++ {
for i := range 16 {
if size == 1<<i {
correctSize = true

Expand Down
12 changes: 4 additions & 8 deletions internal/rtpbuffer/rtpbuffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ func TestRTPBuffer(t *testing.T) {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 511, 512, 513, 32767, 32768, 32769,
65527, 65528, 65529, 65530, 65531, 65532, 65533, 65534, 65535,
} {
start := start

sb, err := NewRTPBuffer(8)
require.NoError(t, err)

Expand Down Expand Up @@ -74,8 +72,6 @@ func TestRTPBuffer_WithRTX(t *testing.T) {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 511, 512, 513, 32767, 32768, 32769,
65527, 65528, 65529, 65530, 65531, 65532, 65533, 65534, 65535,
} {
start := start

sb, err := NewRTPBuffer(8)
require.NoError(t, err)

Expand Down Expand Up @@ -226,14 +222,14 @@ func TestRTPBuffer_Clear(t *testing.T) {
require.NoError(t, err)

// Add packets and verify they exist
for i := uint16(0); i < 8; i++ {
for i := range uint16(8) {
pkt, pktErr := pm.NewPacket(&rtp.Header{SequenceNumber: i}, []byte("payload"), 0, 0)
require.NoError(t, pktErr)
sb.Add(pkt)
}

// Verify packets are in buffer
for i := uint16(0); i < 8; i++ {
for i := range uint16(8) {
pkt := sb.Get(i)
require.NotNil(t, pkt, "packet %d should exist before Clear", i)
pkt.Release()
Expand Down Expand Up @@ -264,7 +260,7 @@ func TestRTPBuffer_ClearReleasesPacketsToPool(t *testing.T) {

// Add packets and track their ref counts
packets := make([]*RetainablePacket, 4)
for i := uint16(0); i < 4; i++ {
for i := range uint16(4) {
pkt, err := pm.NewPacket(&rtp.Header{SequenceNumber: i}, []byte("data"), 0, 0)
require.NoError(t, err)
packets[i] = pkt
Expand All @@ -290,7 +286,7 @@ func TestRTPBuffer_ClearPartiallyFilled(t *testing.T) {
require.NoError(t, err)

// Only add 3 packets to an 8-slot buffer
for i := uint16(0); i < 3; i++ {
for i := range uint16(3) {
pkt, err := pm.NewPacket(&rtp.Header{SequenceNumber: i}, []byte("data"), 0, 0)
require.NoError(t, err)
sb.Add(pkt)
Expand Down
6 changes: 3 additions & 3 deletions pkg/flexfec/encoder_interceptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func TestFecInterceptor_GenerateAndWriteFecPackets(t *testing.T) {
}

var mediaPacketsCount, fecPacketsCount int
for i := 0; i < 3; i++ {
for range 3 {
select {
case packet := <-stream.WrittenRTP():
switch packet.PayloadType {
Expand Down Expand Up @@ -355,7 +355,7 @@ func TestFecInterceptor_HandleMultipleStreamsCorrectly(t *testing.T) {

mediaPacketsCount1 := 0
fecPacketsCount1 := 0
for i := 0; i < 3; i++ {
for range 3 {
select {
case packet := <-stream1.WrittenRTP():
switch packet.SSRC {
Expand All @@ -373,7 +373,7 @@ func TestFecInterceptor_HandleMultipleStreamsCorrectly(t *testing.T) {

mediaPacketsCount2 := 0
fecPacketsCount2 := 0
for i := 0; i < 3; i++ {
for range 3 {
select {
case packet := <-stream2.WrittenRTP():
switch packet.SSRC {
Expand Down
6 changes: 3 additions & 3 deletions pkg/flexfec/flexfec_03_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const (
func checkAnyPacketCanBeRecovered(t *testing.T, mediaPackets []rtp.Packet, fecPackets []rtp.Packet) {
t.Helper()

for lost := 0; lost < len(mediaPackets); lost++ {
for lost := range mediaPackets {
decoder := newFECDecoder(ssrc, protectedStreamSSRC, logging.NewDefaultLoggerFactory())
recoveredPackets := make([]rtp.Packet, 0)
// lose one packet
Expand Down Expand Up @@ -88,7 +88,7 @@ func runEncoderDecoderParityTest(t *testing.T, seqStart uint16, seqLen int, fecC
t.Helper()

seqs := make([]uint16, seqLen)
for i := 0; i < seqLen; i++ {
for i := range seqLen {
seqs[i] = seqStart + uint16(i) //nolint:gosec // G115
}

Expand Down Expand Up @@ -129,7 +129,7 @@ func TestFlexFec03_SimpleRoundTrip(t *testing.T) {
func TestFlexFec03_WholeRangeRoundTrip(t *testing.T) {
var seqs []uint16
const maxFlexFEC03MediaPackets = 109
for i := 0; i < maxFlexFEC03MediaPackets; i++ {
for i := range maxFlexFEC03MediaPackets {
seqs = append(seqs, uint16(i)) //nolint:gosec
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/flexfec/flexfec_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const (
// generateMediaPackets creates a slice of RTP packets with fixed-size payloads.
func generateMediaPackets(n int, startSeq uint16) []rtp.Packet {
mediaPackets := make([]rtp.Packet, 0, n)
for i := 0; i < n; i++ {
for i := range n {
payload := []byte{
// Payload with some random data
1, 2, 3, 4, 5, byte(i),
Expand Down Expand Up @@ -47,14 +47,14 @@ func generateMediaPackets(n int, startSeq uint16) []rtp.Packet {
func generateMediaPacketsWithSizes(n int, startSeq uint16, minSize, maxSize int) []rtp.Packet {
mediaPackets := make([]rtp.Packet, 0, n)

for i := 0; i < n; i++ {
for i := range n {
// Calculate a size that varies between minSize and maxSize based on the packet index
size := minSize + (i % (maxSize - minSize + 1))

// Create a payload of the calculated size
payload := make([]byte, size)
// Fill with some pattern data
for j := 0; j < size; j++ {
for j := range size {
payload[j] = byte((j + i) % 256)
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/flexfec/flexfec_coverage.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func NewCoverage(mediaPackets []rtp.Packet, numFecPackets uint32) *ProtectionCov

// We allocate the biggest array of bitmasks that respects the max constraints.
var packetMasks [MaxFecPackets]util.BitArray
for i := 0; i < int(MaxFecPackets); i++ {
for i := range int(MaxFecPackets) {
packetMasks[i] = util.BitArray{}
}

Expand Down Expand Up @@ -86,7 +86,7 @@ func (p *ProtectionCoverage) UpdateCoverage(mediaPackets []rtp.Packet, numFecPac
// In the packetMasks array, each FEC packet is represented by a single BitArray, each bit in a given BitArray
// corresponds to a specific Media packet.
// Ex: Row I, Col J is set to 1 -> FEC packet I will protect media packet J.
for fecPacketIndex := uint32(0); fecPacketIndex < numFecPackets; fecPacketIndex++ {
for fecPacketIndex := range numFecPackets {
// We use an interleaved method to determine coverage. Given N FEC packets, Media packet X will be
// covered by FEC packet X % N.
coveredMediaPacketIndex := fecPacketIndex
Expand All @@ -99,7 +99,7 @@ func (p *ProtectionCoverage) UpdateCoverage(mediaPackets []rtp.Packet, numFecPac

// ResetCoverage clears the underlying map so that we can reuse it for new batches of RTP packets.
func (p *ProtectionCoverage) resetCoverage() {
for i := uint32(0); i < MaxFecPackets; i++ {
for i := range MaxFecPackets {
p.packetMasks[i].Reset()
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/flexfec/flexfec_decoder_03.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func (d *fecDecoder) recoverPacket(fec *fecPacketState) (rtp.Packet, error) {
return rtp.Packet{}, fmt.Errorf("marshal received header: %w", err)
}
binary.BigEndian.PutUint16(receivedHeader[2:4], uint16(protectedPacket.packet.MarshalSize()-12)) //nolint:gosec
for i := 0; i < 8; i++ {
for i := range 8 {
headerRecovery[i] ^= receivedHeader[i]
}
} else {
Expand Down Expand Up @@ -312,7 +312,7 @@ func (d *fecDecoder) discardOldRecoveredPackets() {

func decodeMask(mask uint64, bitCount uint16, seqNumBase uint16) []uint16 {
res := make([]uint16, 0)
for i := uint16(0); i < bitCount; i++ {
for i := range bitCount {
if (mask>>(bitCount-1-i))&1 == 1 {
res = append(res, seqNumBase+i)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/flexfec/flexfec_encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (flex *FlexEncoder20) EncodeFec(mediaPackets []rtp.Packet, numFecPackets ui

// Generate FEC payloads
fecPackets := make([]rtp.Packet, numFecPackets)
for fecPacketIndex := uint32(0); fecPacketIndex < numFecPackets; fecPacketIndex++ {
for fecPacketIndex := range numFecPackets {
fecPackets[fecPacketIndex] = flex.encodeFlexFecPacket(fecPacketIndex, mediaPackets[0].SequenceNumber)
}

Expand Down Expand Up @@ -200,7 +200,7 @@ func (flex *FlexEncoder20) encodeFlexFecRepairPayload(mediaPackets *util.MediaPa
copy(flexFecPayloadTmp, flexFecPayload)
flexFecPayload = flexFecPayloadTmp
}
for byteIndex := 0; byteIndex < len(mediaPacketPayload); byteIndex++ {
for byteIndex := range mediaPacketPayload {
flexFecPayload[byteIndex] ^= mediaPacketPayload[byteIndex]
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/flexfec/flexfec_encoder_03.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (flex *FlexEncoder03) EncodeFec(mediaPackets []rtp.Packet, numFecPackets ui

// Generate FEC payloads
fecPackets := make([]rtp.Packet, 0, numFecPackets)
for fecPacketIndex := uint32(0); fecPacketIndex < numFecPackets; fecPacketIndex++ {
for fecPacketIndex := range numFecPackets {
fecPacket, ok := flex.encodeFlexFecPacket(fecPacketIndex, mediaPackets[0].SequenceNumber)
if ok {
fecPackets = append(fecPackets, fecPacket)
Expand Down
1 change: 0 additions & 1 deletion pkg/gcc/adaptive_threshold_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ func TestAdaptiveThreshold(t *testing.T) {
}

for _, tc := range cases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
threshold := newAdaptiveThreshold(tc.options...)
usages := []usage{}
Expand Down
1 change: 0 additions & 1 deletion pkg/gcc/arrival_group_accumulator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ func TestArrivalGroupAccumulator(t *testing.T) {
}

for _, tc := range cases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
aga := newArrivalGroupAccumulator()
in := make(chan []cc.Acknowledgment)
Expand Down
1 change: 0 additions & 1 deletion pkg/gcc/arrival_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ func TestArrivalGroup(t *testing.T) {
}

for _, tc := range cases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
ag := arrivalGroup{}
for i, ack := range tc.acks {
Expand Down
1 change: 0 additions & 1 deletion pkg/gcc/gcc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ func TestClamp(t *testing.T) {
},
}
for i, tt := range tests {
tt := tt
t.Run(fmt.Sprintf("int/%v", i), func(t *testing.T) {
assert.Equal(t, tt.expected, clampInt(tt.x, tt.min, tt.max))
})
Expand Down
1 change: 0 additions & 1 deletion pkg/gcc/kalman_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ func TestKalman(t *testing.T) {
},
}
for _, tc := range cases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
k := newKalman(append(tc.opts, setDisableMeasurementUncertaintyUpdates(true))...)
estimates := []time.Duration{}
Expand Down
1 change: 0 additions & 1 deletion pkg/gcc/overuse_detector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ func TestOveruseDetectorWithoutDelay(t *testing.T) {
},
}
for _, tc := range cases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
out := make(chan DelayStats)
dsw := func(ds DelayStats) {
Expand Down
3 changes: 1 addition & 2 deletions pkg/gcc/rate_calculator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ func TestRateCalculator(t *testing.T) {
}

for _, tc := range cases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
rc := newRateCalculator(500 * time.Millisecond)
in := make(chan []cc.Acknowledgment)
Expand Down Expand Up @@ -106,7 +105,7 @@ func TestRateCalculator(t *testing.T) {
func getACKStream(length int, size int, interval time.Duration) []cc.Acknowledgment {
res := []cc.Acknowledgment{}
t0 := time.Now()
for i := 0; i < length; i++ {
for range length {
res = append(res, cc.Acknowledgment{
Size: size,
Arrival: t0,
Expand Down
1 change: 0 additions & 1 deletion pkg/gcc/rate_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ func TestRateControllerRun(t *testing.T) {
return t0
}
for _, tc := range cases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
out := make(chan DelayStats)
dc := newRateController(mockNoFn, 100_000, 1_000, 50_000_000, func(ds DelayStats) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/gcc/send_side_bwe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func BenchmarkSendSideBWE_WriteRTCP(b *testing.B) {
for i := 0; i < b.N; i++ {
// nolint:gosec
seqs := rand.Intn(count/2) + count // [count, count * 1.5)
for j := 0; j < seqs; j++ {
for range seqs {
seq++

if rand.Intn(5) != 0 { //nolint:gosec
Expand Down
1 change: 0 additions & 1 deletion pkg/gcc/slope_estimator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ func TestSlopeEstimator(t *testing.T) {
}

for _, tc := range cases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
out := make(chan DelayStats)
se := newSlopeEstimator(estimatorFunc(identity), func(ds DelayStats) {
Expand Down
Loading
Loading