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 codecs/av1/obu/leb128.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func ReadLeb128(in []byte) (uint, uint, error) {
func WriteToLeb128(in uint) []byte {
b := make([]byte, 10)

for i := 0; i < len(b); i++ {
for i := range len(b) {
b[i] = byte(in & 0x7f)
in >>= 7
if in == 0 {
Expand Down
2 changes: 0 additions & 2 deletions codecs/av1/obu/leb128_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ func TestLEB128(t *testing.T) {
{5, 5},
{999999, 0xBF843D},
} {
test := test

encoded := EncodeLEB128(test.Value)
assert.Equal(t, test.Encoded, encoded)

Expand Down
7 changes: 1 addition & 6 deletions codecs/av1/obu/obu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func TestOBUType(t *testing.T) {
{Type(0), 0, "OBU_RESERVED"},
{Type(9), 9, "OBU_RESERVED"},
} {
test := test
assert.Equal(t, test.Str, test.Type.String())
assert.Equal(t, test.TypeValue, uint8(test.Type))
}
Expand Down Expand Up @@ -55,8 +54,6 @@ func TestOBUHeader_NoExtension(t *testing.T) {
}

for _, test := range tests {
test := test

buff := []byte{test.Value}
header, err := ParseOBUHeader(buff)
assert.NoError(t, err)
Expand Down Expand Up @@ -115,8 +112,6 @@ func TestOBUHeader_Extension(t *testing.T) {
}

for _, test := range tests {
test := test

buff := []byte{test.HeaderValue, test.ExtensionHeaderValue}
header, err := ParseOBUHeader(buff)
assert.NoError(t, err)
Expand Down Expand Up @@ -213,7 +208,7 @@ func TestOBUMarshal_HasOBUSize(t *testing.T) {
const payloadSize = 128
payload := make([]byte, payloadSize)

for i := 0; i < payloadSize; i++ {
for i := range payloadSize {
payload[i] = byte(i)
}

Expand Down
5 changes: 2 additions & 3 deletions codecs/av1_packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1564,7 +1564,7 @@ func TestAV1Payloader_SequenceHeader(t *testing.T) {
func TestAv1Payloader_FragmentedEdgeLeb128Size(t *testing.T) {
size := uint16(128)
payload := make([]byte, 0, size)
for i := uint16(0); i < size; i++ {
for i := range size {
payload = append(payload, byte(i))
}

Expand Down Expand Up @@ -1836,7 +1836,6 @@ func TestAV1_Unmarshal_Error(t *testing.T) {
{obu.ErrFailedToReadLEB128, []byte{byte(0b10000000), 0xFF, 0xFF}},
{errShortPacket, []byte{byte(0b10000000), 0xFF, 0x0F, 0x00, 0x00}},
} {
test := test
av1Pkt := &AV1Packet{}

_, err := av1Pkt.Unmarshal(test.input)
Expand Down Expand Up @@ -2082,7 +2081,7 @@ func FuzzAV1PayloaderPayloadMTU(f *testing.F) {
largePayload := make([]byte, 0, 5000)
largePayload = append(largePayload, frameHeader...)
largePayload = append(largePayload, 0xFF, 0x26)
for i := 0; i < 5000; i++ {
for i := range 5000 {
largePayload = append(largePayload, byte(i%256))
}
f.Add(uint16(1500), largePayload)
Expand Down
4 changes: 2 additions & 2 deletions codecs/h264_packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ func TestH264Payloader_Payload(t *testing.T) {
// Multiple NALU in a single payload
res = pck.Payload(5, multiplepayload)
assert.Len(t, res, 2, "2 nal units should be broken out")
for i := 0; i < 2; i++ {
for i := range 2 {
assert.Lenf(t, res[i], 1, "Payload %d of 2 is packed incorrectly", i+1)
}

// Multiple NALU in a single payload with 3-byte and 4-byte start sequences
res = pck.Payload(5, mixednalupayload)
assert.Len(t, res, 4, "4 nal units should be broken out")
for i := 0; i < 4; i++ {
for i := range 4 {
assert.Lenf(t, res[i], 1, "Payload %d of 4 is packed incorrectly", i+1)
}

Expand Down
12 changes: 6 additions & 6 deletions codecs/h265_packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ func TestH265Payloader_Real(t *testing.T) {
func TestH265_FragmentationMtu(t *testing.T) {
payload := make([]byte, 2000)

for i := 0; i < 2000; i++ {
for i := range 2000 {
payload[i] = uint8(i) //nolint: gosec // idc
}

Expand Down Expand Up @@ -429,7 +429,7 @@ func TestH265_FragmentationRoundtrip(t *testing.T) {
payload := make([]byte, 0)
testDonl := uint16(100)

for i := 0; i < 200; i++ {
for i := range 200 {
payload = append(payload, uint8(i)) //nolint: gosec // idc
}

Expand Down Expand Up @@ -497,7 +497,7 @@ func TestH265_AggregationRoundtrip(t *testing.T) {

withDonlCount := uint16(4)
withDonl := make([]h265SingleNALUnitPacket, withDonlCount)
for i := uint16(0); i < withDonlCount; i++ {
for i := range withDonlCount {
donlVal := i
withDonl[i] = h265SingleNALUnitPacket{
createTestH265Header(0, 0, 1, false),
Expand Down Expand Up @@ -610,7 +610,7 @@ func TestH265_SingleRoundtrip(t *testing.T) {

withDonlCount := uint16(4)
withDonl := make([]h265SingleNALUnitPacket, withDonlCount)
for i := uint16(0); i < withDonlCount; i++ {
for i := range withDonlCount {
donlVal := i
withDonl[i] = h265SingleNALUnitPacket{
createTestH265Header(0, 0, 1, false),
Expand Down Expand Up @@ -691,7 +691,7 @@ func TestH265Packetizer_Fragmented(t *testing.T) {
bigPacket = binary.BigEndian.AppendUint16(bigPacket, uint16(header))

payload := make([]byte, 0)
for i := 0; i < 50; i++ {
for range 50 {
payload = append(payload, 0xff)
}
bigPacket = append(bigPacket, payload...)
Expand Down Expand Up @@ -793,7 +793,7 @@ func TestH265Depacketizer_Roundtrip(t *testing.T) {
nil,
make([]byte, 0),
}
for i := 0; i < 512; i++ {
for i := range 512 {
largePacket.payload = append(largePacket.payload, uint8(i)) // nolint:gosec
}

Expand Down
12 changes: 6 additions & 6 deletions codecs/h266_packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func TestH266_FragmentationRoundtrip(t *testing.T) {
payload := make([]byte, 0)
testDonl := uint16(100)

for i := 0; i < 200; i++ {
for i := range 200 {
payload = append(payload, uint8(i)) //nolint: gosec // idc
}

Expand Down Expand Up @@ -253,7 +253,7 @@ func TestH266_FragmentationHeader(t *testing.T) {
make([]byte, 0),
}

for i := 0; i < 1000; i++ {
for i := range 1000 {
simplePacket.payload = append(simplePacket.payload, uint8(i)) //nolint: gosec // idc
}

Expand Down Expand Up @@ -281,7 +281,7 @@ func TestH266_FragmentationEdgeCase(t *testing.T) {
make([]byte, 0),
}

for i := 0; i < 200; i++ {
for i := range 200 {
simplePacket.payload = append(simplePacket.payload, uint8(i)) //nolint: gosec // idc
}

Expand All @@ -294,7 +294,7 @@ func TestH266_FragmentationEdgeCase(t *testing.T) {
// Exactly large enough to fill one FU

simplePacket.payload = make([]byte, 0)
for i := 0; i < 100; i++ {
for i := range 100 {
simplePacket.payload = append(simplePacket.payload, uint8(i)) //nolint: gosec // idc
}

Expand Down Expand Up @@ -510,7 +510,7 @@ func TestH266Packetizer_Fragmented(t *testing.T) {
bigPacket = binary.BigEndian.AppendUint16(bigPacket, uint16(header))

payload := make([]byte, 0)
for i := 0; i < 50; i++ {
for range 50 {
payload = append(payload, 0xff)
}
bigPacket = append(bigPacket, payload...)
Expand Down Expand Up @@ -613,7 +613,7 @@ func TestH266Depacketizer_Roundtrip(t *testing.T) {
nil,
make([]byte, 0),
}
for i := 0; i < 512; i++ {
for i := range 512 {
largePacket.payload = append(largePacket.payload, uint8(i)) // nolint:gosec
}

Expand Down
7 changes: 5 additions & 2 deletions codecs/vp8_packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,17 @@ func (p *VP8Packet) Unmarshal(payload []byte) ([]byte, error) { //nolint:gocogni
if payloadIndex >= payloadLen {
return nil, errShortPacket
}
//nolint:gosec // G602: payloadIndex bounds checked above
if payload[payloadIndex]&0x80 > 0 { // M == 1, PID is 16bit
if payloadIndex+1 >= payloadLen {
return nil, errShortPacket
}
p.PictureID = (uint16(payload[payloadIndex]&0x7F) << 8) | uint16(payload[payloadIndex+1])
//nolint:gosec // G602: payloadIndex bounds checked above
p.PictureID = (uint16(payload[payloadIndex]&0x7F) << 8) |
uint16(payload[payloadIndex+1])
payloadIndex += 2
} else {
p.PictureID = uint16(payload[payloadIndex])
p.PictureID = uint16(payload[payloadIndex]) //nolint:gosec
payloadIndex++
}
} else {
Expand Down
1 change: 0 additions & 1 deletion codecs/vp8_packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ func TestVP8Payloader_Payload(t *testing.T) {
},
}
for name, testCase := range testCases {
testCase := testCase
t.Run(name, func(t *testing.T) {
pck := testCase.payloader

Expand Down
4 changes: 2 additions & 2 deletions codecs/vp9_packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (p *VP9Payloader) payloadFlexible(mtu uint16, payload []byte) [][]byte {
}

out[1] = byte(p.pictureID>>8) | 0x80
out[2] = byte(p.pictureID)
out[2] = byte(p.pictureID) //nolint:gosec

copy(out[headerSize:], payload[payloadDataIndex:payloadDataIndex+currentFragmentSize])
payloads = append(payloads, out)
Expand Down Expand Up @@ -169,7 +169,7 @@ func (p *VP9Payloader) payloadNonFlexible(mtu uint16, payload []byte) [][]byte {
}

out[1] = byte(p.pictureID>>8) | 0x80
out[2] = byte(p.pictureID)
out[2] = byte(p.pictureID) //nolint:gosec
off := 3

if !header.NonKeyFrame && payloadDataIndex == 0 {
Expand Down
8 changes: 3 additions & 5 deletions codecs/vp9_packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,6 @@ func TestVP9Packet_Unmarshal(t *testing.T) {
},
}
for name, testCase := range cases {
testCase := testCase

t.Run(name, func(t *testing.T) {
p := VP9Packet{}
raw, err := p.Unmarshal(testCase.b)
Expand All @@ -226,8 +224,8 @@ func TestVP9Packet_Unmarshal(t *testing.T) {
func TestVP9Payloader_Payload(t *testing.T) {
r0 := int(rand.New(rand.NewSource(0)).Int31n(0x7FFF)) //nolint:gosec
var rands [][2]byte
for i := 0; i < 10; i++ {
rands = append(rands, [2]byte{byte(r0>>8) | 0x80, byte(r0 & 0xFF)})
for range 10 {
rands = append(rands, [2]byte{byte(r0>>8) | 0x80, byte(r0 & 0xFF)}) //nolint:gosec // r0 is bounded to 0x7FFF
r0++
}

Expand Down Expand Up @@ -376,7 +374,7 @@ func TestVP9Payloader_Payload(t *testing.T) {
},
}
pPrev := VP9Packet{}
for i := 0; i < 0x8000; i++ {
for i := range 0x8000 {
res := pck.Payload(4, []byte{0x01})
packet := VP9Packet{}
_, err := packet.Unmarshal(res[0])
Expand Down
2 changes: 1 addition & 1 deletion packetizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestPacketizer(t *testing.T) {
if len(packets) != expectedLen {
var packetlengths strings.Builder
for i := range packets {
packetlengths.WriteString(fmt.Sprintf("Packet %d length %d\n", i, len(packets[i].Payload)))
fmt.Fprintf(&packetlengths, "Packet %d length %d\n", i, len(packets[i].Payload))
}
assert.Failf(
t, "Packetize failed", "Generated %d packets instead of %d\n%s",
Expand Down
8 changes: 4 additions & 4 deletions playoutdelayextension.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ func (p PlayoutDelayExtension) MarshalTo(buf []byte) (int, error) {
return 0, io.ErrShortBuffer
}
buf[0] = byte(p.MinDelay >> 4)
buf[1] = byte(p.MinDelay<<4) | byte(p.MaxDelay>>8)
buf[2] = byte(p.MaxDelay)
buf[1] = byte(p.MinDelay<<4) | byte(p.MaxDelay>>8) //nolint:gosec
buf[2] = byte(p.MaxDelay) //nolint:gosec

return playoutDelayExtensionSize, nil
}
Expand All @@ -57,8 +57,8 @@ func (p PlayoutDelayExtension) Marshal() ([]byte, error) {

return []byte{
byte(p.MinDelay >> 4),
byte(p.MinDelay<<4) | byte(p.MaxDelay>>8),
byte(p.MaxDelay),
byte(p.MinDelay<<4) | byte(p.MaxDelay>>8), //nolint:gosec
byte(p.MaxDelay), //nolint:gosec
}, nil
}

Expand Down
5 changes: 3 additions & 2 deletions vlaextension.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (v VLA) MarshalTo(buf []byte) (int, error) { //nolint:cyclop,gocognit
offset := 0

// RID, NS, sl_bm fields
buf[offset] = byte(v.RTPStreamID<<6) | byte(v.RTPStreamCount-1)<<4 | ctx.commonSLBM
buf[offset] = byte(v.RTPStreamID<<6) | byte(v.RTPStreamCount-1)<<4 | ctx.commonSLBM //nolint:gosec // values are small

if ctx.commonSLBM == 0 {
offset++
Expand All @@ -182,6 +182,7 @@ func (v VLA) MarshalTo(buf []byte) (int, error) { //nolint:cyclop,gocognit
temporalLayerIndex = 0
offset++
}
//nolint:gosec // values are small
buf[offset] |= byte(len(v.ActiveSpatialLayer[idx].TargetBitrates)-1) << (2 * (3 - temporalLayerIndex))
temporalLayerIndex++
}
Expand All @@ -205,7 +206,7 @@ func (v VLA) MarshalTo(buf []byte) (int, error) { //nolint:cyclop,gocognit
for _, sl := range v.ActiveSpatialLayer {
binary.BigEndian.PutUint16(buf[offset+0:], uint16(sl.Width-1)) //nolint:gosec
binary.BigEndian.PutUint16(buf[offset+2:], uint16(sl.Height-1)) //nolint:gosec
buf[offset+4] = byte(sl.Framerate)
buf[offset+4] = byte(sl.Framerate) //nolint:gosec
offset += 5
}
}
Expand Down
Loading