diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 5016c181..4ee028b8 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -10,16 +10,19 @@ jobs: golangci-lint: runs-on: ubuntu-22.04 + env: + CGO_ENABLED: '0' + steps: - uses: actions/checkout@v4 - uses: actions/setup-go@v3 with: - go-version: "1.22" + go-version: "1.23" - uses: golangci/golangci-lint-action@v3 with: - version: v1.59.1 + version: v1.61.0 go-mod-tidy: runs-on: ubuntu-22.04 @@ -29,7 +32,7 @@ jobs: - uses: actions/setup-go@v3 with: - go-version: "1.22" + go-version: "1.23" - run: | go mod tidy diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 94efa598..59ff467c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-22.04 strategy: matrix: - go: ["1.20", "1.21", "1.22"] + go: ["1.21", "1.22", "1.23"] steps: - uses: actions/checkout@v4 @@ -24,7 +24,7 @@ jobs: - run: make test-nodocker - - if: matrix.go == '1.22' + - if: matrix.go == '1.23' uses: codecov/codecov-action@v3 with: token: ${{ secrets.CODECOV_TOKEN }} @@ -37,7 +37,7 @@ jobs: - uses: actions/setup-go@v3 with: - go-version: "1.22" + go-version: "1.23" - run: make test-highlevel-nodocker diff --git a/Makefile b/Makefile index 920ff7eb..68d1a87f 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -BASE_IMAGE = golang:1.22-alpine3.18 -LINT_IMAGE = golangci/golangci-lint:v1.59.1 +BASE_IMAGE = golang:1.23-alpine3.20 +LINT_IMAGE = golangci/golangci-lint:v1.61.0 .PHONY: $(shell ls) diff --git a/README.md b/README.md index 73084462..95c51619 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ RTSP 1.0 client and server library for the Go programming language, written for [MediaMTX](https://github.com/bluenviron/mediamtx). -Go ≥ 1.20 is required. +Go ≥ 1.21 is required. Features: diff --git a/client.go b/client.go index 54791f18..85cb0e8c 100644 --- a/client.go +++ b/client.go @@ -1914,7 +1914,7 @@ func (c *Client) PacketPTS(medi *description.Media, pkt *rtp.Packet) (time.Durat return multiplyAndDivide(time.Duration(v), time.Second, time.Duration(ct.format.ClockRate())), true } -// PacketPTS returns the PTS of an incoming RTP packet. +// PacketPTS2 returns the PTS of an incoming RTP packet. // It is computed by decoding the packet timestamp and sychronizing it with other tracks. func (c *Client) PacketPTS2(medi *description.Media, pkt *rtp.Packet) (int64, bool) { cm := c.medias[medi] diff --git a/client_udp_listener.go b/client_udp_listener.go index c47cabcd..6c0fc575 100644 --- a/client_udp_listener.go +++ b/client_udp_listener.go @@ -15,8 +15,8 @@ func int64Ptr(v int64) *int64 { return &v } -func randInRange(max int) (int, error) { - b := big.NewInt(int64(max + 1)) +func randInRange(maxVal int) (int, error) { + b := big.NewInt(int64(maxVal + 1)) n, err := rand.Int(rand.Reader, b) if err != nil { return 0, err diff --git a/examples/client-play-format-h264-convert-to-jpeg/main.go b/examples/client-play-format-h264-convert-to-jpeg/main.go index 2f574348..352176dc 100644 --- a/examples/client-play-format-h264-convert-to-jpeg/main.go +++ b/examples/client-play-format-h264-convert-to-jpeg/main.go @@ -1,3 +1,6 @@ +//go:build cgo +// +build cgo + package main import ( diff --git a/examples/client-play-format-h264/main.go b/examples/client-play-format-h264/main.go index 45697964..989e48db 100644 --- a/examples/client-play-format-h264/main.go +++ b/examples/client-play-format-h264/main.go @@ -1,3 +1,6 @@ +//go:build cgo +// +build cgo + package main import ( diff --git a/examples/client-play-format-h265-convert-to-jpeg/main.go b/examples/client-play-format-h265-convert-to-jpeg/main.go index 8d80fb62..426b9c6d 100644 --- a/examples/client-play-format-h265-convert-to-jpeg/main.go +++ b/examples/client-play-format-h265-convert-to-jpeg/main.go @@ -1,3 +1,6 @@ +//go:build cgo +// +build cgo + package main import ( diff --git a/examples/client-play-format-h265/main.go b/examples/client-play-format-h265/main.go index d3a01886..33c42148 100644 --- a/examples/client-play-format-h265/main.go +++ b/examples/client-play-format-h265/main.go @@ -1,3 +1,6 @@ +//go:build cgo +// +build cgo + package main import ( diff --git a/go.mod b/go.mod index 13df6ead..8df2906f 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/bluenviron/gortsplib/v4 -go 1.20 +go 1.21 require ( github.com/bluenviron/mediacommon v1.13.1 diff --git a/pkg/format/format_test.go b/pkg/format/format_test.go index ec92d952..b05dd0f0 100644 --- a/pkg/format/format_test.go +++ b/pkg/format/format_test.go @@ -743,7 +743,8 @@ var casesFormat = []struct { "s=\n" + "m=video 0 RTP/AVP 96\n" + "a=rtpmap:96 MP4V-ES/90000\n" + - "a=fmtp:96 profile-level-id=1; config=000001B001000001B58913000001000000012000C48D8AEE053C04641443000001B24C61766335382E3133342E313030\n", + "a=fmtp:96 profile-level-id=1; " + + "config=000001B001000001B58913000001000000012000C48D8AEE053C04641443000001B24C61766335382E3133342E313030\n", &MPEG4Video{ PayloadTyp: 96, ProfileLevelID: 1, @@ -770,7 +771,8 @@ var casesFormat = []struct { "s=\n" + "m=video 0 RTP/AVP 96\n" + "a=rtpmap:96 H264/90000\n" + - "a=fmtp:96 packetization-mode=1; profile-level-id=64000C; sprop-parameter-sets=Z2QADKw7ULBLQgAAAwACAAADAD0I,aO48gA==\n", + "a=fmtp:96 packetization-mode=1; profile-level-id=64000C; " + + "sprop-parameter-sets=Z2QADKw7ULBLQgAAAwACAAADAD0I,aO48gA==\n", &H264{ PayloadTyp: 96, SPS: []byte{ @@ -797,7 +799,8 @@ var casesFormat = []struct { "s=\n" + "m=video 0 RTP/AVP 96\n" + "a=rtpmap:96 H264/90000\n" + - "a=fmtp:96 packetization-mode=1; profile-level-id=64001f; sprop-parameter-sets=Z2QAH6zZQFAFuwFsgAAAAwCAAAAeB4wYyw==,aOvjyyLA\n", + "a=fmtp:96 packetization-mode=1; profile-level-id=64001f; " + + "sprop-parameter-sets=Z2QAH6zZQFAFuwFsgAAAAwCAAAAeB4wYyw==,aOvjyyLA\n", &H264{ PayloadTyp: 96, SPS: []byte{ @@ -825,7 +828,8 @@ var casesFormat = []struct { "s=\n" + "m=video 0 RTP/AVP 96\n" + "a=rtpmap:96 H264/90000\n" + - "a=fmtp:96 packetization-mode=1; profile-level-id=640029; sprop-parameter-sets=Z2QAKawTMUB4BEfeA+oCAgPgAAADACAAAAZSgA==,aPqPLA==,aF6jzAMA\n", + "a=fmtp:96 packetization-mode=1; profile-level-id=640029; " + + "sprop-parameter-sets=Z2QAKawTMUB4BEfeA+oCAgPgAAADACAAAAZSgA==,aPqPLA==,aF6jzAMA\n", &H264{ PayloadTyp: 96, SPS: []byte{ @@ -870,7 +874,8 @@ var casesFormat = []struct { "s=\n" + "m=video 0 RTP/AVP 96\n" + "a=rtpmap:96 H264/90000\n" + - "a=fmtp:96 packetization-mode=1; profile-level-id=4DE028; sprop-parameter-sets=AAAAAWdNAB6NjUBaHtCAAAOEAACvyAI=,AAAAAWjuOIA=\n", + "a=fmtp:96 packetization-mode=1; profile-level-id=4DE028; " + + "sprop-parameter-sets=AAAAAWdNAB6NjUBaHtCAAAOEAACvyAI=,AAAAAWjuOIA=\n", &H264{ PayloadTyp: 96, SPS: []byte{ @@ -897,7 +902,8 @@ var casesFormat = []struct { "s=\n" + "m=video 0 RTP/AVP 96\n" + "a=rtpmap:96 H264/90000\n" + - "a=fmtp:96 packetization-mode=1; profile-level-id=010101; sprop-parameter-sets=QgEBAWAAAAMAAAMAAAMAAAMAlqADwIAQ5Y2uSTJrlnAIAAADAAgAAAMAyEA=,RAHgdrAmQA==\n", + "a=fmtp:96 packetization-mode=1; profile-level-id=010101; " + + "sprop-parameter-sets=QgEBAWAAAAMAAAMAAAMAAAMAlqADwIAQ5Y2uSTJrlnAIAAADAAgAAAMAyEA=,RAHgdrAmQA==\n", &H264{ PayloadTyp: 96, PacketizationMode: 1, @@ -966,7 +972,8 @@ var casesFormat = []struct { "s=\n" + "m=video 0 RTP/AVP 96\n" + "a=rtpmap:96 H265/90000\n" + - "a=fmtp:96 sprop-vps=QAEMAf//AWAAAAMAkAAAAwAAAwB4mZgJ; sprop-sps=QgEBAWAAAAMAkAAAAwAAAwB4oAPAgBDllmZpJMrgEAAAAwAQAAADAeCA; " + + "a=fmtp:96 sprop-vps=QAEMAf//AWAAAAMAkAAAAwAAAwB4mZgJ; " + + "sprop-sps=QgEBAWAAAAMAkAAAAwAAAwB4oAPAgBDllmZpJMrgEAAAAwAQAAADAeCA; " + "sprop-pps=RAHBcrRiQA==; sprop-max-don-diff=2\n", &H265{ PayloadTyp: 96, @@ -1003,7 +1010,8 @@ var casesFormat = []struct { "s=\n" + "m=video 0 RTP/AVP 96\n" + "a=rtpmap:96 H265/90000\n" + - "a=fmtp:96 sprop-vps=AAAAAUABDAH//wFgAAADAAADAAADAAADAJasCQ==; sprop-sps=AAAAAUIBAQFgAAADAAADAAADAAADAJagBaIB4WNrkkya5Zk=; " + + "a=fmtp:96 sprop-vps=AAAAAUABDAH//wFgAAADAAADAAADAAADAJasCQ==; " + + "sprop-sps=AAAAAUIBAQFgAAADAAADAAADAAADAJagBaIB4WNrkkya5Zk=; " + "sprop-pps=AAAAAUQB4HawJkA=\n", &H265{ PayloadTyp: 96, @@ -1224,7 +1232,7 @@ func FuzzUnmarshal(f *testing.F) { err := desc.Unmarshal([]byte(in)) if err == nil && len(desc.MediaDescriptions) == 1 && len(desc.MediaDescriptions[0].MediaName.Formats) == 1 { - Unmarshal(desc.MediaDescriptions[0], desc.MediaDescriptions[0].MediaName.Formats[0]) + Unmarshal(desc.MediaDescriptions[0], desc.MediaDescriptions[0].MediaName.Formats[0]) //nolint:errcheck } }) } diff --git a/pkg/format/h264_test.go b/pkg/format/h264_test.go index a3d143e3..1cda3b4a 100644 --- a/pkg/format/h264_test.go +++ b/pkg/format/h264_test.go @@ -63,7 +63,7 @@ func TestH264DecEncoder(t *testing.T) { } func FuzzH264PTSEqualsDTS(f *testing.F) { - f.Fuzz(func(t *testing.T, b []byte) { + f.Fuzz(func(_ *testing.T, b []byte) { (&H264{}).PTSEqualsDTS(&rtp.Packet{Payload: b}) }) } diff --git a/pkg/format/h265_test.go b/pkg/format/h265_test.go index 20768343..ed1a735b 100644 --- a/pkg/format/h265_test.go +++ b/pkg/format/h265_test.go @@ -72,7 +72,7 @@ func TestH265DecEncoder(t *testing.T) { } func FuzzH265PTSEqualsDTS(f *testing.F) { - f.Fuzz(func(t *testing.T, b []byte) { + f.Fuzz(func(_ *testing.T, b []byte) { (&H265{}).PTSEqualsDTS(&rtp.Packet{Payload: b}) }) } diff --git a/pkg/format/rtpav1/decoder.go b/pkg/format/rtpav1/decoder.go index fb7d47a8..b744e904 100644 --- a/pkg/format/rtpav1/decoder.go +++ b/pkg/format/rtpav1/decoder.go @@ -103,7 +103,8 @@ func (d *Decoder) decodeOBUs(pkt *rtp.Packet) ([][]byte, error) { if d.fragmentsSize > av1.MaxTemporalUnitSize { d.resetFragments() - return nil, fmt.Errorf("temporal unit size (%d) is too big, maximum is %d", d.fragmentsSize, av1.MaxTemporalUnitSize) + return nil, fmt.Errorf("temporal unit size (%d) is too big, maximum is %d", + d.fragmentsSize, av1.MaxTemporalUnitSize) } d.fragments = append(d.fragments, av1header.OBUElements[elementCount-1]) diff --git a/pkg/format/rtpav1/decoder_test.go b/pkg/format/rtpav1/decoder_test.go index d1387aef..a6cde17c 100644 --- a/pkg/format/rtpav1/decoder_test.go +++ b/pkg/format/rtpav1/decoder_test.go @@ -68,7 +68,7 @@ func TestDecodeErrorMissingPacket(t *testing.T) { SequenceNumber: 17645, SSRC: 0x9dbb7812, }, - Payload: []byte{ + Payload: []byte{ //nolint:dupl 0x40, 0xb1, 0x0b, 0x30, 0x30, 0xca, 0x08, 0x12, 0xfd, 0xfd, 0x78, 0x89, 0xe5, 0x3e, 0xa3, 0x80, 0x08, 0x20, 0x82, 0x08, 0x54, 0x50, 0x00, 0x30, diff --git a/pkg/format/rtpav1/encoder_test.go b/pkg/format/rtpav1/encoder_test.go index 450934e6..d5983db1 100644 --- a/pkg/format/rtpav1/encoder_test.go +++ b/pkg/format/rtpav1/encoder_test.go @@ -266,7 +266,7 @@ var cases = []struct { SequenceNumber: 17645, SSRC: 0x9dbb7812, }, - Payload: []byte{ + Payload: []byte{ //nolint:dupl 0x40, 0xb1, 0x0b, 0x30, 0x30, 0xca, 0x08, 0x12, 0xfd, 0xfd, 0x78, 0x89, 0xe5, 0x3e, 0xa3, 0x80, 0x08, 0x20, 0x82, 0x08, 0x54, 0x50, 0x00, 0x30, @@ -523,7 +523,7 @@ var cases = []struct { SequenceNumber: 17645, SSRC: 0x9dbb7812, }, - Payload: []byte{ + Payload: []byte{ //nolint:dupl 0x48, 0x10, 0x0a, 0x0e, 0x00, 0x00, 0x00, 0x4a, 0xab, 0xbf, 0xc3, 0x77, 0x6b, 0xe4, 0x40, 0x40, 0x40, 0x41, 0xa0, 0x0b, 0x30, 0x30, 0xca, 0x08, @@ -717,7 +717,7 @@ var cases = []struct { SequenceNumber: 17646, SSRC: 0x9dbb7812, }, - Payload: []byte{ + Payload: []byte{ //nolint:dupl 0xc0, 0xcc, 0x01, 0x9c, 0x6e, 0x5f, 0x2f, 0x20, 0x78, 0x58, 0x59, 0x92, 0x15, 0xfe, 0x13, 0x07, 0x87, 0xc7, 0x3e, 0x21, 0x04, 0x24, 0x33, 0x60, diff --git a/pkg/format/rtpmpeg4audio/encoder_generic.go b/pkg/format/rtpmpeg4audio/encoder_generic.go index bde46305..90d2adeb 100644 --- a/pkg/format/rtpmpeg4audio/encoder_generic.go +++ b/pkg/format/rtpmpeg4audio/encoder_generic.go @@ -86,8 +86,8 @@ func (e *Encoder) writeGenericFragmented(au []byte, timestamp uint32) ([]*rtp.Pa // AU-headers pos := 0 - bits.WriteBits(payload[2:], &pos, uint64(le), e.SizeLength) - bits.WriteBits(payload[2:], &pos, 0, e.IndexLength) + bits.WriteBitsUnsafe(payload[2:], &pos, uint64(le), e.SizeLength) + bits.WriteBitsUnsafe(payload[2:], &pos, 0, e.IndexLength) // AU copy(payload[2+auHeadersLenBytes:], au) @@ -153,13 +153,13 @@ func (e *Encoder) writeGenericAggregated(aus [][]byte, timestamp uint32) ([]*rtp written := 0 pos := 0 for i, au := range aus { - bits.WriteBits(payload[2:], &pos, uint64(len(au)), e.SizeLength) + bits.WriteBitsUnsafe(payload[2:], &pos, uint64(len(au)), e.SizeLength) written += e.SizeLength if i == 0 { - bits.WriteBits(payload[2:], &pos, 0, e.IndexLength) + bits.WriteBitsUnsafe(payload[2:], &pos, 0, e.IndexLength) written += e.IndexLength } else { - bits.WriteBits(payload[2:], &pos, 0, e.IndexDeltaLength) + bits.WriteBitsUnsafe(payload[2:], &pos, 0, e.IndexDeltaLength) written += e.IndexDeltaLength } } diff --git a/pkg/headers/transport.go b/pkg/headers/transport.go index dc714bf5..e53d2fe5 100644 --- a/pkg/headers/transport.go +++ b/pkg/headers/transport.go @@ -189,8 +189,8 @@ func (h *Transport) Unmarshal(v base.HeaderValue) error { if v != "" { ip := net.ParseIP(v) if ip == nil { - addrs, err := net.LookupHost(v) - if err != nil { + addrs, err2 := net.LookupHost(v) + if err2 != nil { return fmt.Errorf("invalid source (%v)", v) } ip = net.ParseIP(addrs[0]) @@ -211,38 +211,38 @@ func (h *Transport) Unmarshal(v base.HeaderValue) error { } case "interleaved": - ports, err := parsePorts(v) - if err != nil { - return err + ports, err2 := parsePorts(v) + if err2 != nil { + return err2 } h.InterleavedIDs = ports case "ttl": - tmp, err := strconv.ParseUint(v, 10, 32) - if err != nil { - return err + tmp, err2 := strconv.ParseUint(v, 10, 32) + if err2 != nil { + return err2 } vu := uint(tmp) h.TTL = &vu case "port": - ports, err := parsePorts(v) - if err != nil { - return err + ports, err2 := parsePorts(v) + if err2 != nil { + return err2 } h.Ports = ports case "client_port": - ports, err := parsePorts(v) - if err != nil { - return err + ports, err2 := parsePorts(v) + if err2 != nil { + return err2 } h.ClientPorts = ports case "server_port": - ports, err := parsePorts(v) - if err != nil { - return err + ports, err2 := parsePorts(v) + if err2 != nil { + return err2 } h.ServerPorts = ports @@ -253,7 +253,7 @@ func (h *Transport) Unmarshal(v base.HeaderValue) error { v = "0" + v } - if tmp, err := hex.DecodeString(v); err == nil && len(tmp) <= 4 { + if tmp, err2 := hex.DecodeString(v); err2 == nil && len(tmp) <= 4 { var ssrc [4]byte copy(ssrc[4-len(tmp):], tmp) v := uint32(ssrc[0])<<24 | uint32(ssrc[1])<<16 | uint32(ssrc[2])<<8 | uint32(ssrc[3]) diff --git a/pkg/sdp/sdp_test.go b/pkg/sdp/sdp_test.go index 9f18aac9..1396bb74 100644 --- a/pkg/sdp/sdp_test.go +++ b/pkg/sdp/sdp_test.go @@ -3010,7 +3010,8 @@ var cases = []struct { "m=video 0 RTP/AVP 96\r\n" + "a=control:trackID=0\r\n" + "a=rtpmap:96 H264/90000\r\n" + - "a=fmtp:96 packetization-mode=1; sprop-parameter-sets=Z00AMpY1QFEBf03AQEBAgA==,aO4xsg==; profile-level-id=4D0032\r\n" + + "a=fmtp:96 packetization-mode=1; sprop-parameter-sets=Z00AMpY1QFEBf03AQEBAgA==,aO4xsg==; " + + "profile-level-id=4D0032\r\n" + "m=audio 0 RTP/AVP 14\r\n" + "a=control:trackID=1\r\n" + "m=text 0 RTP/AVP 103\r\n" + @@ -3023,7 +3024,8 @@ var cases = []struct { "m=video 0 RTP/AVP 96\r\n" + "a=control:trackID=0\r\n" + "a=rtpmap:96 H264/90000\r\n" + - "a=fmtp:96 packetization-mode=1; sprop-parameter-sets=Z00AMpY1QFEBf03AQEBAgA==,aO4xsg==; profile-level-id=4D0032\r\n" + + "a=fmtp:96 packetization-mode=1; sprop-parameter-sets=Z00AMpY1QFEBf03AQEBAgA==,aO4xsg==; " + + "profile-level-id=4D0032\r\n" + "m=audio 0 RTP/AVP 14\r\n" + "a=control:trackID=1\r\n" + "m=text 0 RTP/AVP 103\r\n" + @@ -3060,8 +3062,9 @@ var cases = []struct { Value: "96 H264/90000", }, { - Key: "fmtp", - Value: "96 packetization-mode=1; sprop-parameter-sets=Z00AMpY1QFEBf03AQEBAgA==,aO4xsg==; profile-level-id=4D0032", + Key: "fmtp", + Value: "96 packetization-mode=1; sprop-parameter-sets=Z00AMpY1QFEBf03AQEBAgA==,aO4xsg==; " + + "profile-level-id=4D0032", }, }, }, diff --git a/scripts/lint.mk b/scripts/lint.mk index 9c73673c..a15abc47 100644 --- a/scripts/lint.mk +++ b/scripts/lint.mk @@ -1,4 +1,5 @@ lint: docker run --rm -v $(PWD):/app -w /app \ + -e CGO_ENABLED=0 \ $(LINT_IMAGE) \ golangci-lint run -v diff --git a/server_record_test.go b/server_record_test.go index 040a842b..f325a470 100644 --- a/server_record_test.go +++ b/server_record_test.go @@ -206,8 +206,7 @@ func TestServerRecordErrorSetup(t *testing.T) { var inTH *headers.Transport - switch ca.name { - case "invalid transport": + if ca.name == "invalid transport" { inTH = &headers.Transport{ Delivery: deliveryPtr(headers.TransportDeliveryUnicast), Mode: nil,