diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index c875c137..9e496479 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -19,7 +19,7 @@ jobs: - uses: golangci/golangci-lint-action@v3 with: - version: v1.50.1 + version: v1.52.2 go-mod-tidy: runs-on: ubuntu-20.04 diff --git a/Makefile b/Makefile index 34e2ad84..d2fdf8ab 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ BASE_IMAGE = golang:1.20.1-alpine3.17 -LINT_IMAGE = golangci/golangci-lint:v1.50.1 +LINT_IMAGE = golangci/golangci-lint:v1.52.2 .PHONY: $(shell ls) diff --git a/client.go b/client.go index 3a634417..994d72a4 100644 --- a/client.go +++ b/client.go @@ -481,7 +481,7 @@ func (c *Client) runInner() error { req.res <- clientRes{res: res, err: err} case req := <-c.play: - res, err := c.doPlay(req.ra, false) + res, err := c.doPlay(req.ra) req.res <- clientRes{res: res, err: err} case req := <-c.record: @@ -607,7 +607,7 @@ func (c *Client) trySwitchingProtocol() error { } } - _, err = c.doPlay(c.lastRange, true) + _, err = c.doPlay(c.lastRange) if err != nil { return err } @@ -1423,7 +1423,7 @@ func (c *Client) SetupAll(medias media.Medias, baseURL *url.URL) error { return nil } -func (c *Client) doPlay(ra *headers.Range, isSwitchingProtocol bool) (*base.Response, error) { +func (c *Client) doPlay(ra *headers.Range) (*base.Response, error) { err := c.checkState(map[clientState]struct{}{ clientStatePrePlay: {}, }) diff --git a/client_media.go b/client_media.go index 47c1d6fd..34f678c3 100644 --- a/client_media.go +++ b/client_media.go @@ -126,8 +126,8 @@ func (cm *clientMedia) start() { } if cm.udpRTPListener != nil { - cm.udpRTPListener.start(cm.c.state == clientStatePlay) - cm.udpRTCPListener.start(cm.c.state == clientStatePlay) + cm.udpRTPListener.start() + cm.udpRTCPListener.start() } for _, ct := range cm.formats { @@ -241,7 +241,7 @@ func (cm *clientMedia) readRTCPTCPPlay(payload []byte) error { return nil } -func (cm *clientMedia) readRTPTCPRecord(payload []byte) error { +func (cm *clientMedia) readRTPTCPRecord(_ []byte) error { return nil } @@ -323,7 +323,7 @@ func (cm *clientMedia) readRTCPUDPPlay(payload []byte) error { return nil } -func (cm *clientMedia) readRTPUDPRecord(payload []byte) error { +func (cm *clientMedia) readRTPUDPRecord(_ []byte) error { return nil } diff --git a/client_udp_listener.go b/client_udp_listener.go index 98d48b1b..f3069866 100644 --- a/client_udp_listener.go +++ b/client_udp_listener.go @@ -153,11 +153,11 @@ func (u *clientUDPListener) port() int { return u.pc.LocalAddr().(*net.UDPAddr).Port } -func (u *clientUDPListener) start(forPlay bool) { +func (u *clientUDPListener) start() { u.running = true u.pc.SetReadDeadline(time.Time{}) u.readerDone = make(chan struct{}) - go u.runReader(forPlay) + go u.runReader() } func (u *clientUDPListener) stop() { @@ -165,7 +165,7 @@ func (u *clientUDPListener) stop() { <-u.readerDone } -func (u *clientUDPListener) runReader(forPlay bool) { +func (u *clientUDPListener) runReader() { defer close(u.readerDone) var readFunc func([]byte) error diff --git a/pkg/formats/av1.go b/pkg/formats/av1.go index e73de756..47eac772 100644 --- a/pkg/formats/av1.go +++ b/pkg/formats/av1.go @@ -18,7 +18,7 @@ type AV1 struct { Tier *int } -func (f *AV1) unmarshal(payloadType uint8, clock string, codec string, rtpmap string, fmtp map[string]string) error { +func (f *AV1) unmarshal(payloadType uint8, _ string, _ string, _ string, fmtp map[string]string) error { f.PayloadTyp = payloadType for key, val := range fmtp { diff --git a/pkg/formats/g711.go b/pkg/formats/g711.go index da8427d4..f201499b 100644 --- a/pkg/formats/g711.go +++ b/pkg/formats/g711.go @@ -13,7 +13,7 @@ type G711 struct { MULaw bool } -func (f *G711) unmarshal(payloadType uint8, clock string, codec string, rtpmap string, fmtp map[string]string) error { +func (f *G711) unmarshal(payloadType uint8, _ string, _ string, _ string, _ map[string]string) error { f.MULaw = (payloadType == 0) return nil } diff --git a/pkg/formats/g722.go b/pkg/formats/g722.go index 43ae702d..192b342d 100644 --- a/pkg/formats/g722.go +++ b/pkg/formats/g722.go @@ -10,7 +10,7 @@ import ( // Specification: https://datatracker.ietf.org/doc/html/rfc3551 type G722 struct{} -func (f *G722) unmarshal(payloadType uint8, clock string, codec string, rtpmap string, fmtp map[string]string) error { +func (f *G722) unmarshal(_ uint8, _ string, _ string, _ string, _ map[string]string) error { return nil } diff --git a/pkg/formats/generic.go b/pkg/formats/generic.go index 2e4a5b52..820832c7 100644 --- a/pkg/formats/generic.go +++ b/pkg/formats/generic.go @@ -57,20 +57,17 @@ type Generic struct { RTPMa string FMT map[string]string - // clock rate of the format. Filled automatically. + // clock rate of the format. Filled when calling Init(). ClockRat int } -// Init computes the clock rate of the format. It it mandatory to call it. +// Init computes the clock rate of the format. It is mandatory to call it. func (f *Generic) Init() error { f.ClockRat, _ = findClockRate(f.PayloadTyp, f.RTPMa) return nil } -func (f *Generic) unmarshal( - payloadType uint8, clock string, codec string, - rtpmap string, fmtp map[string]string, -) error { +func (f *Generic) unmarshal(payloadType uint8, _ string, _ string, rtpmap string, fmtp map[string]string) error { f.PayloadTyp = payloadType f.RTPMa = rtpmap f.FMT = fmtp diff --git a/pkg/formats/h264.go b/pkg/formats/h264.go index 9fd78a01..37526d29 100644 --- a/pkg/formats/h264.go +++ b/pkg/formats/h264.go @@ -81,7 +81,7 @@ type H264 struct { mutex sync.RWMutex } -func (f *H264) unmarshal(payloadType uint8, clock string, codec string, rtpmap string, fmtp map[string]string) error { +func (f *H264) unmarshal(payloadType uint8, _ string, _ string, _ string, fmtp map[string]string) error { f.PayloadTyp = payloadType for key, val := range fmtp { diff --git a/pkg/formats/h265.go b/pkg/formats/h265.go index e3d3a63f..9c3727b3 100644 --- a/pkg/formats/h265.go +++ b/pkg/formats/h265.go @@ -23,7 +23,7 @@ type H265 struct { mutex sync.RWMutex } -func (f *H265) unmarshal(payloadType uint8, clock string, codec string, rtpmap string, fmtp map[string]string) error { +func (f *H265) unmarshal(payloadType uint8, _ string, _ string, _ string, fmtp map[string]string) error { f.PayloadTyp = payloadType for key, val := range fmtp { diff --git a/pkg/formats/lpcm.go b/pkg/formats/lpcm.go index f342b9e9..b08728d0 100644 --- a/pkg/formats/lpcm.go +++ b/pkg/formats/lpcm.go @@ -18,7 +18,7 @@ type LPCM struct { ChannelCount int } -func (f *LPCM) unmarshal(payloadType uint8, clock string, codec string, rtpmap string, fmtp map[string]string) error { +func (f *LPCM) unmarshal(payloadType uint8, clock string, codec string, _ string, _ map[string]string) error { f.PayloadTyp = payloadType switch codec { diff --git a/pkg/formats/mjpeg.go b/pkg/formats/mjpeg.go index 0370a537..f627dc23 100644 --- a/pkg/formats/mjpeg.go +++ b/pkg/formats/mjpeg.go @@ -10,7 +10,7 @@ import ( // Specification: https://datatracker.ietf.org/doc/html/rfc2435 type MJPEG struct{} -func (f *MJPEG) unmarshal(payloadType uint8, clock string, codec string, rtpmap string, fmtp map[string]string) error { +func (f *MJPEG) unmarshal(_ uint8, _ string, _ string, _ string, _ map[string]string) error { return nil } diff --git a/pkg/formats/mpeg2_audio.go b/pkg/formats/mpeg2_audio.go index 5822de7a..4924423d 100644 --- a/pkg/formats/mpeg2_audio.go +++ b/pkg/formats/mpeg2_audio.go @@ -10,10 +10,7 @@ import ( // Specification: https://datatracker.ietf.org/doc/html/rfc2250 type MPEG2Audio struct{} -func (f *MPEG2Audio) unmarshal( - payloadType uint8, clock string, codec string, - rtpmap string, fmtp map[string]string, -) error { +func (f *MPEG2Audio) unmarshal(_ uint8, _ string, _ string, _ string, _ map[string]string) error { return nil } diff --git a/pkg/formats/mpeg2_video.go b/pkg/formats/mpeg2_video.go index 4ae5182e..774af0e3 100644 --- a/pkg/formats/mpeg2_video.go +++ b/pkg/formats/mpeg2_video.go @@ -8,10 +8,7 @@ import ( // Specification: https://datatracker.ietf.org/doc/html/rfc2250 type MPEG2Video struct{} -func (f *MPEG2Video) unmarshal( - payloadType uint8, clock string, codec string, - rtpmap string, fmtp map[string]string, -) error { +func (f *MPEG2Video) unmarshal(_ uint8, _ string, _ string, _ string, _ map[string]string) error { return nil } diff --git a/pkg/formats/mpeg4_audio_generic.go b/pkg/formats/mpeg4_audio_generic.go index dcc62d1a..cb0ead86 100644 --- a/pkg/formats/mpeg4_audio_generic.go +++ b/pkg/formats/mpeg4_audio_generic.go @@ -27,8 +27,8 @@ type MPEG4AudioGeneric struct { } func (f *MPEG4AudioGeneric) unmarshal( - payloadType uint8, clock string, codec string, - rtpmap string, fmtp map[string]string, + payloadType uint8, _ string, _ string, + _ string, fmtp map[string]string, ) error { f.PayloadTyp = payloadType diff --git a/pkg/formats/mpeg4_audio_latm.go b/pkg/formats/mpeg4_audio_latm.go index 5ddfdc18..1c7a5359 100644 --- a/pkg/formats/mpeg4_audio_latm.go +++ b/pkg/formats/mpeg4_audio_latm.go @@ -21,8 +21,8 @@ type MPEG4AudioLATM struct { } func (f *MPEG4AudioLATM) unmarshal( - payloadType uint8, clock string, codec string, - rtpmap string, fmtp map[string]string, + payloadType uint8, _ string, _ string, + _ string, fmtp map[string]string, ) error { f.PayloadTyp = payloadType f.ProfileLevelID = 30 // default value defined by specification diff --git a/pkg/formats/mpeg4_video_es.go b/pkg/formats/mpeg4_video_es.go index f1e65fa6..896b4fdb 100644 --- a/pkg/formats/mpeg4_video_es.go +++ b/pkg/formats/mpeg4_video_es.go @@ -23,8 +23,8 @@ type MPEG4VideoES struct { } func (f *MPEG4VideoES) unmarshal( - payloadType uint8, clock string, codec string, - rtpmap string, fmtp map[string]string, + payloadType uint8, _ string, _ string, + _ string, fmtp map[string]string, ) error { f.PayloadTyp = payloadType f.ProfileLevelID = 1 // default value defined by specification diff --git a/pkg/formats/mpegts.go b/pkg/formats/mpegts.go index d057517c..f65d81a7 100644 --- a/pkg/formats/mpegts.go +++ b/pkg/formats/mpegts.go @@ -8,7 +8,7 @@ import ( // Specification: https://datatracker.ietf.org/doc/html/rfc2250 type MPEGTS struct{} -func (f *MPEGTS) unmarshal(payloadType uint8, clock string, codec string, rtpmap string, fmtp map[string]string) error { +func (f *MPEGTS) unmarshal(_ uint8, _ string, _ string, _ string, _ map[string]string) error { return nil } diff --git a/pkg/formats/opus.go b/pkg/formats/opus.go index 0753ca0b..07a99d8f 100644 --- a/pkg/formats/opus.go +++ b/pkg/formats/opus.go @@ -17,7 +17,7 @@ type Opus struct { IsStereo bool } -func (f *Opus) unmarshal(payloadType uint8, clock string, codec string, rtpmap string, fmtp map[string]string) error { +func (f *Opus) unmarshal(payloadType uint8, clock string, _ string, _ string, fmtp map[string]string) error { f.PayloadTyp = payloadType tmp := strings.SplitN(clock, "/", 2) diff --git a/pkg/formats/vorbis.go b/pkg/formats/vorbis.go index 8287bf68..4ce35b52 100644 --- a/pkg/formats/vorbis.go +++ b/pkg/formats/vorbis.go @@ -18,7 +18,7 @@ type Vorbis struct { Configuration []byte } -func (f *Vorbis) unmarshal(payloadType uint8, clock string, codec string, rtpmap string, fmtp map[string]string) error { +func (f *Vorbis) unmarshal(payloadType uint8, clock string, _ string, _ string, fmtp map[string]string) error { f.PayloadTyp = payloadType tmp := strings.SplitN(clock, "/", 2) diff --git a/pkg/formats/vp8.go b/pkg/formats/vp8.go index e83a4260..9ff69772 100644 --- a/pkg/formats/vp8.go +++ b/pkg/formats/vp8.go @@ -17,7 +17,7 @@ type VP8 struct { MaxFS *int } -func (f *VP8) unmarshal(payloadType uint8, clock string, codec string, rtpmap string, fmtp map[string]string) error { +func (f *VP8) unmarshal(payloadType uint8, _ string, _ string, _ string, fmtp map[string]string) error { f.PayloadTyp = payloadType for key, val := range fmtp { diff --git a/pkg/formats/vp9.go b/pkg/formats/vp9.go index ac085771..e7661bc2 100644 --- a/pkg/formats/vp9.go +++ b/pkg/formats/vp9.go @@ -18,7 +18,7 @@ type VP9 struct { ProfileID *int } -func (f *VP9) unmarshal(payloadType uint8, clock string, codec string, rtpmap string, fmtp map[string]string) error { +func (f *VP9) unmarshal(payloadType uint8, _ string, _ string, _ string, fmtp map[string]string) error { f.PayloadTyp = payloadType for key, val := range fmtp { diff --git a/pkg/headers/keyval.go b/pkg/headers/keyval.go index 07229c01..11515971 100644 --- a/pkg/headers/keyval.go +++ b/pkg/headers/keyval.go @@ -4,7 +4,7 @@ import ( "fmt" ) -func readKey(origstr string, str string, separator byte) (string, string) { +func readKey(str string, separator byte) (string, string) { i := 0 for { if i >= len(str) || str[i] == '=' || str[i] == separator { @@ -47,7 +47,7 @@ func keyValParse(str string, separator byte) (map[string]string, error) { for len(str) > 0 { var k string - k, str = readKey(origstr, str, separator) + k, str = readKey(str, separator) if len(k) > 0 { if len(str) > 0 && str[0] == '=' { diff --git a/server_conn.go b/server_conn.go index 356ec22f..068e9f20 100644 --- a/server_conn.go +++ b/server_conn.go @@ -26,10 +26,10 @@ func getSessionID(header base.Header) string { func mediasForSDP( medias media.Medias, - streamMedias map[*media.Media]*serverStreamMedia, contentBase *url.URL, ) media.Medias { - copy := make(media.Medias, len(medias)) + newMedias := make(media.Medias, len(medias)) + for i, medi := range medias { mc := &media.Media{ Type: medi.Type, @@ -47,9 +47,10 @@ func mediasForSDP( u, _ := mc.URL(contentBase) mc.Control = u.String() - copy[i] = mc + newMedias[i] = mc } - return copy + + return newMedias } type readReq struct { @@ -294,7 +295,7 @@ func (sc *ServerConn) handleRequestInner(req *base.Request) (*base.Response, err } if stream != nil { - byts, _ := mediasForSDP(stream.medias, stream.streamMedias, req.URL).Marshal(multicast).Marshal() + byts, _ := mediasForSDP(stream.medias, req.URL).Marshal(multicast).Marshal() res.Body = byts } } diff --git a/server_conn_reader.go b/server_conn_reader.go index 5566e315..70b15c9d 100644 --- a/server_conn_reader.go +++ b/server_conn_reader.go @@ -68,12 +68,12 @@ func (cr *serverConnReader) readFuncStandard() error { cr.sc.nconn.SetReadDeadline(time.Time{}) for { - any, err := cr.sc.conn.ReadInterleavedFrameOrRequest() + what, err := cr.sc.conn.ReadInterleavedFrameOrRequest() if err != nil { return err } - switch what := any.(type) { + switch what := what.(type) { case *base.Request: cres := make(chan error) req := readReq{req: what, res: cres} diff --git a/server_record_test.go b/server_record_test.go index eba73ed0..d469f8b7 100644 --- a/server_record_test.go +++ b/server_record_test.go @@ -66,7 +66,8 @@ func invalidURLAnnounceReq(t *testing.T, control string) base.Request { MediaDescriptions: []*psdp.MediaDescription{medi.Marshal()}, } - byts, _ := sout.Marshal() + byts, err := sout.Marshal() + require.NoError(t, err) return base.Request{ Method: base.Announce, diff --git a/server_session_media.go b/server_session_media.go index b534b7e3..0bc7ad07 100644 --- a/server_session_media.go +++ b/server_session_media.go @@ -240,7 +240,7 @@ func (sm *serverSessionMedia) readRTCPUDPRecord(payload []byte) error { return nil } -func (sm *serverSessionMedia) readRTPTCPPlay(payload []byte) error { +func (sm *serverSessionMedia) readRTPTCPPlay(_ []byte) error { return nil } diff --git a/server_test.go b/server_test.go index 349332e0..d59f782f 100644 --- a/server_test.go +++ b/server_test.go @@ -323,7 +323,7 @@ type testServerErrMethodNotImplemented struct { } func (s *testServerErrMethodNotImplemented) OnDescribe( - ctx *ServerHandlerOnDescribeCtx, + _ *ServerHandlerOnDescribeCtx, ) (*base.Response, *ServerStream, error) { return &base.Response{ StatusCode: base.StatusOK, @@ -331,7 +331,7 @@ func (s *testServerErrMethodNotImplemented) OnDescribe( } func (s *testServerErrMethodNotImplemented) OnSetup( - ctx *ServerHandlerOnSetupCtx, + _ *ServerHandlerOnSetupCtx, ) (*base.Response, *ServerStream, error) { return &base.Response{ StatusCode: base.StatusOK,