Skip to content
Draft
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
16 changes: 8 additions & 8 deletions abscapturetimeextension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,35 +104,35 @@ var (
func BenchmarkAbsCaptureTimeExtension_Marshal(b *testing.B) {
ext := NewAbsCaptureTimeExtension(time.Now())
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {

for b.Loop() {
absCaptureTimeSink, _ = ext.Marshal()
}
}

func BenchmarkAbsCaptureTimeExtension_MarshalTo(b *testing.B) {
ext := NewAbsCaptureTimeExtension(time.Now())
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {

for b.Loop() {
absCaptureTimeSinkInt, _ = ext.MarshalTo(absCaptureTimeBuf)
}
}

func BenchmarkAbsCaptureTimeExtensionWithOffset_Marshal(b *testing.B) {
ext := NewAbsCaptureTimeExtensionWithCaptureClockOffset(time.Now(), 100*time.Millisecond)
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {

for b.Loop() {
absCaptureTimeSink, _ = ext.Marshal()
}
}

func BenchmarkAbsCaptureTimeExtensionWithOffset_MarshalTo(b *testing.B) {
ext := NewAbsCaptureTimeExtensionWithCaptureClockOffset(time.Now(), 100*time.Millisecond)
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {

for b.Loop() {
absCaptureTimeSinkInt, _ = ext.MarshalTo(absCaptureTimeExtendedBuf)
}
}
8 changes: 4 additions & 4 deletions abssendtimeextension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,17 @@ var (
func BenchmarkAbsSendTimeExtension_Marshal(b *testing.B) {
ext := AbsSendTimeExtension{Timestamp: 123456}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {

for b.Loop() {
absSendTimeSink, _ = ext.Marshal()
}
}

func BenchmarkAbsSendTimeExtension_MarshalTo(b *testing.B) {
ext := AbsSendTimeExtension{Timestamp: 123456}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {

for b.Loop() {
absSendTimeSinkInt, _ = ext.MarshalTo(absSendTimeBuf)
}
}
8 changes: 4 additions & 4 deletions audiolevelextension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,17 @@ var (
func BenchmarkAudioLevelExtension_Marshal(b *testing.B) {
ext := AudioLevelExtension{Level: 8, Voice: true}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {

for b.Loop() {
audioLevelSink, _ = ext.Marshal()
}
}

func BenchmarkAudioLevelExtension_MarshalTo(b *testing.B) {
ext := AudioLevelExtension{Level: 8, Voice: true}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {

for b.Loop() {
audioLevelSinkInt, _ = ext.MarshalTo(audioLevelBuf)
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/pion/rtp

go 1.21
go 1.24

Check failure on line 3 in go.mod

View workflow job for this annotation

GitHub Actions / lint / Metadata

Invalid Go version

Found 1.24. Expected 1.21

require (
github.com/pion/randutil v0.1.0
Expand Down
1 change: 0 additions & 1 deletion header_extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ func TestHeaderExtension_RFC8285OneByteMultipleExtensionsWithPadding(t *testing.
dstBuf["DirtyBuffer"][i] = 0xFF
}
for name, buf := range dstBuf {
buf := buf
t.Run(name, func(t *testing.T) {
n, err := ext.MarshalTo(buf)
assert.NoError(t, err)
Expand Down
13 changes: 3 additions & 10 deletions packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestBasic(t *testing.T) { // nolint:maintidx,cyclop
}

// Unmarshal to the used Packet should work as well.
for i := 0; i < 2; i++ {
for i := range 2 {
t.Run(fmt.Sprintf("Run%d", i+1), func(t *testing.T) {
assert.NoError(t, packet.Unmarshal(rawPkt))
assert.Equal(t, packet, parsedPacket)
Expand Down Expand Up @@ -433,7 +433,6 @@ func TestRFC8285OneByteMultipleExtensionsWithPadding(t *testing.T) {
dstBuf["DirtyBuffer"][i] = 0xFF
}
for name, buf := range dstBuf {
buf := buf
t.Run(name, func(t *testing.T) {
n, err := packet.MarshalTo(buf)
assert.NoError(t, err)
Expand Down Expand Up @@ -577,7 +576,6 @@ func TestRFC8285TwoByteMultipleExtensionsWithPadding(t *testing.T) {
dstBuf["DirtyBuffer"][i] = 0xFF
}
for name, buf := range dstBuf {
buf := buf
t.Run(name, func(t *testing.T) {
n, err := packet.MarshalTo(buf)
assert.NoError(t, err)
Expand Down Expand Up @@ -1200,7 +1198,6 @@ func TestUnmarshal_ErrorHandling(t *testing.T) {
}

for name, testCase := range cases {
testCase := testCase
t.Run(name, func(t *testing.T) {
h := &Header{}
_, err := h.Unmarshal(testCase.input)
Expand Down Expand Up @@ -1488,9 +1485,7 @@ func BenchmarkMarshal(b *testing.B) {
b.Fatal(err)
}

b.ResetTimer()

for i := 0; i < b.N; i++ {
for b.Loop() {
_, err = packet.Marshal()
if err != nil {
b.Fatal(err)
Expand All @@ -1513,9 +1508,7 @@ func BenchmarkMarshalTo(b *testing.B) {

buf := [100]byte{}

b.ResetTimer()

for i := 0; i < b.N; i++ {
for b.Loop() {
_, err = packet.MarshalTo(buf[:])
if err != nil {
b.Fatal(err)
Expand Down
11 changes: 6 additions & 5 deletions packetizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package rtp

import (
"fmt"
"strings"
"testing"
"time"

Expand All @@ -20,13 +21,13 @@ func TestPacketizer(t *testing.T) {

expectedLen := 2
if len(packets) != expectedLen {
packetlengths := ""
for i := 0; i < len(packets); i++ {
packetlengths += fmt.Sprintf("Packet %d length %d\n", i, len(packets[i].Payload))
var packetlengths strings.Builder
for i := range packets {
packetlengths.WriteString(fmt.Sprintf("Packet %d length %d\n", i, len(packets[i].Payload)))
}
assert.Failf(
t, "Packetize failed", "Generated %d packets instead of %d\n%s",
len(packets), expectedLen, packetlengths,
len(packets), expectedLen, packetlengths.String(),
)
}
}
Expand Down Expand Up @@ -188,7 +189,7 @@ func TestPacketizer_Empty_Payload(t *testing.T) {
const expectedSamples = uint32(4000)

prevTimestamp := uint32(0)
for i := 0; i < 10; i++ {
for i := range 10 {
payload := []byte{0x11, 0x12, 0x13, 0x14}
isEmptyPayload := i%2 == 0
if isEmptyPayload {
Expand Down
8 changes: 4 additions & 4 deletions playoutdelayextension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,17 @@ var (
func BenchmarkPlayoutDelayExtension_Marshal(b *testing.B) {
ext := PlayoutDelayExtension{MinDelay: 100, MaxDelay: 200}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {

for b.Loop() {
playoutDelaySink, _ = ext.Marshal()
}
}

func BenchmarkPlayoutDelayExtension_MarshalTo(b *testing.B) {
ext := PlayoutDelayExtension{MinDelay: 100, MaxDelay: 200}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {

for b.Loop() {
playoutDelaySinkInt, _ = ext.MarshalTo(playoutDelayBuf)
}
}
10 changes: 5 additions & 5 deletions sequencer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestSequencerMultipleRollovers(t *testing.T) {
sequencer.NextSequenceNumber()
assert.Equal(t, uint64(1), sequencer.RollOverCount())

for i := 0; i < 65536; i++ {
for range 65536 {
sequencer.NextSequenceNumber()
}

Expand All @@ -55,11 +55,11 @@ func TestSequencerConcurrent(t *testing.T) {
wg.Add(numGoroutines)

results := make([][]uint16, numGoroutines)
for i := 0; i < numGoroutines; i++ {
for i := range numGoroutines {
go func(idx int) {
defer wg.Done()
results[idx] = make([]uint16, numIterations)
for j := 0; j < numIterations; j++ {
for j := range numIterations {
results[idx][j] = sequencer.NextSequenceNumber()
}
}(i)
Expand All @@ -68,8 +68,8 @@ func TestSequencerConcurrent(t *testing.T) {
wg.Wait()

seen := make(map[uint16]int)
for i := 0; i < numGoroutines; i++ {
for j := 0; j < numIterations; j++ {
for i := range numGoroutines {
for j := range numIterations {
seen[results[i][j]]++
}
}
Expand Down
8 changes: 4 additions & 4 deletions transportccextension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,17 @@ var (
func BenchmarkTransportCCExtension_Marshal(b *testing.B) {
ext := TransportCCExtension{TransportSequence: 1234}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {

for b.Loop() {
transportCCSink, _ = ext.Marshal()
}
}

func BenchmarkTransportCCExtension_MarshalTo(b *testing.B) {
ext := TransportCCExtension{TransportSequence: 1234}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {

for b.Loop() {
transportCCSinkInt, _ = ext.MarshalTo(transportCCBuf)
}
}
10 changes: 5 additions & 5 deletions vlaextension.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (v VLA) preprocessForMashaling(ctx *vlaMarshalingContext) error { //nolint:

func (v VLA) calcTargetBitratesSize(ctx *vlaMarshalingContext) {
for rtpStreamID := 0; rtpStreamID < v.RTPStreamCount; rtpStreamID++ {
for spatialID := 0; spatialID < 4; spatialID++ {
for spatialID := range 4 {
if idx := ctx.slIndices[rtpStreamID][spatialID]; idx >= 0 {
for _, kbps := range v.ActiveSpatialLayer[idx].TargetBitrates {
ctx.requiredLen += leb128Size(uint(kbps)) //nolint:gosec
Expand Down Expand Up @@ -176,7 +176,7 @@ func (v VLA) MarshalTo(buf []byte) (int, error) { //nolint:cyclop,gocognit
offset++
var temporalLayerIndex int
for rtpStreamID := 0; rtpStreamID < v.RTPStreamCount; rtpStreamID++ {
for spatialID := 0; spatialID < 4; spatialID++ {
for spatialID := range 4 {
if idx := ctx.slIndices[rtpStreamID][spatialID]; idx >= 0 {
if temporalLayerIndex >= 4 {
temporalLayerIndex = 0
Expand All @@ -191,7 +191,7 @@ func (v VLA) MarshalTo(buf []byte) (int, error) { //nolint:cyclop,gocognit
// Target bitrate fields
offset++
for rtpStreamID := 0; rtpStreamID < v.RTPStreamCount; rtpStreamID++ {
for spatialID := 0; spatialID < 4; spatialID++ {
for spatialID := range 4 {
if idx := ctx.slIndices[rtpStreamID][spatialID]; idx >= 0 {
for _, kbps := range v.ActiveSpatialLayer[idx].TargetBitrates {
offset += writeLeb128To(buf[offset:], uint(kbps)) //nolint:gosec
Expand Down Expand Up @@ -231,7 +231,7 @@ func (v VLA) Marshal() ([]byte, error) {

func commonSLBMValues(slMBs []uint8) uint8 {
var common uint8
for i := 0; i < len(slMBs); i++ {
for i := range slMBs {
if slMBs[i] == 0 {
continue
}
Expand Down Expand Up @@ -301,7 +301,7 @@ func (v *VLA) unmarshalTemporalLayers(ctx *vlaUnmarshalingContext) error { // no

var temporalLayerIndex int
for streamID := 0; streamID < v.RTPStreamCount; streamID++ {
for spatialID := 0; spatialID < 4; spatialID++ {
for spatialID := range 4 {
if ctx.slBMs[streamID]&(1<<spatialID) == 0 {
continue
}
Expand Down
14 changes: 7 additions & 7 deletions vlaextension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,8 @@ func TestVLAUnmarshal(t *testing.T) {
func TestVLAMarshalThenUnmarshal(t *testing.T) {
t.Run("multiple spatial layers", func(t *testing.T) {
var spatialLayers []SpatialLayer
for streamID := 0; streamID < 3; streamID++ {
for spatialID := 0; spatialID < 4; spatialID++ {
for streamID := range 3 {
for spatialID := range 4 {
spatialLayers = append(spatialLayers, SpatialLayer{
RTPStreamID: streamID,
SpatialID: spatialID,
Expand Down Expand Up @@ -410,7 +410,7 @@ func TestVLAMarshalThenUnmarshal(t *testing.T) {

t.Run("different spatial layer bitmasks", func(t *testing.T) {
var spatialLayers []SpatialLayer
for streamID := 0; streamID < 4; streamID++ {
for streamID := range 4 {
for spatialID := 0; spatialID < streamID+1; spatialID++ {
spatialLayers = append(spatialLayers, SpatialLayer{
RTPStreamID: streamID,
Expand Down Expand Up @@ -503,8 +503,8 @@ func BenchmarkVLA_Marshal(b *testing.B) {
},
}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {

for b.Loop() {
vlaSink, _ = vla.Marshal()
}
}
Expand All @@ -520,8 +520,8 @@ func BenchmarkVLA_MarshalTo(b *testing.B) {
},
}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {

for b.Loop() {
vlaSinkInt, _ = vla.MarshalTo(vlaBuf)
}
}
Loading