From 71861bd1325cb2f8e8ffc1f3af2f97950a738f1f Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Sat, 5 Dec 2020 18:44:05 +0100 Subject: [PATCH] switch to golangci-lint --- .github/workflows/lint.yml | 25 ++++++++++++++ Makefile | 12 ++++++- README.md | 2 +- clientconn.go | 52 +++++++++++++++--------------- clientconnpublish.go | 34 +++++++++---------- clientconnread.go | 44 ++++++++++++------------- clientconnudpl.go | 14 ++++---- clientdialer_test.go | 14 ++++---- connserver.go | 4 +-- examples/client-publish-options.go | 2 +- examples/client-publish-pause.go | 2 +- examples/client-publish.go | 2 +- pkg/auth/package_test.go | 12 +++---- pkg/base/interleavedframe.go | 12 +++---- pkg/base/request.go | 32 +++++++++--------- pkg/multibuffer/multibuffer.go | 2 +- pkg/rtcpreceiver/rtcpreceiver.go | 2 +- pkg/rtpaac/encoder.go | 2 +- pkg/sdp/sdp_test.go | 1 + track.go | 24 +++++++------- 20 files changed, 165 insertions(+), 129 deletions(-) create mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 00000000..02511d81 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,25 @@ +name: lint + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + lint: + name: lint + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - uses: golangci/golangci-lint-action@v2 + with: + version: v1.33 + args: > + --disable=errcheck + --enable=gofmt + --enable=golint + --enable=misspell diff --git a/Makefile b/Makefile index 249a037a..95264348 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,8 @@ help: @echo "" @echo " mod-tidy run go mod tidy" @echo " format format source files" - @echo " test run available tests" + @echo " test run tests" + @echo " lint run linter" @echo "" blank := @@ -51,3 +52,12 @@ test-nodocker: docker build -q testimages/$(IMG) -t gortsplib-test-$(IMG)$(NL)) go test -race -v ./... $(foreach f,$(shell ls examples/*),go build -o /dev/null $(f)$(NL)) + +lint: + docker run --rm -v $(PWD):/app -w /app \ + golangci/golangci-lint:v1.33.0 \ + golangci-lint run -v \ + --disable=errcheck \ + --enable=gofmt \ + --enable=golint \ + --enable=misspell diff --git a/README.md b/README.md index 0ccfc6ed..2b4a7c32 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # gortsplib [![Test](https://github.com/aler9/gortsplib/workflows/test/badge.svg)](https://github.com/aler9/gortsplib/actions) -[![Go Report Card](https://goreportcard.com/badge/github.com/aler9/gortsplib)](https://goreportcard.com/report/github.com/aler9/gortsplib) +[![Lint](https://github.com/aler9/gortsplib/workflows/lint/badge.svg)](https://github.com/aler9/gortsplib/actions) [![PkgGoDev](https://pkg.go.dev/badge/github.com/aler9/gortsplib)](https://pkg.go.dev/github.com/aler9/gortsplib) RTSP 1.0 client and server library for the Go programming language, written for [rtsp-simple-server](https://github.com/aler9/rtsp-simple-server). diff --git a/clientconn.go b/clientconn.go index da4c2484..9f629f73 100644 --- a/clientconn.go +++ b/clientconn.go @@ -71,7 +71,7 @@ type ConnClient struct { cseq int auth *auth.Client state connClientState - streamUrl *base.URL + streamURL *base.URL streamProtocol *StreamProtocol tracks Tracks udpRtpListeners map[int]*connClientUDPListener @@ -104,8 +104,8 @@ func (c *ConnClient) Close() error { <-c.backgroundDone c.Do(&base.Request{ - Method: base.TEARDOWN, - URL: c.streamUrl, + Method: base.Teardown, + URL: c.streamURL, SkipResponse: true, }) } @@ -172,7 +172,7 @@ func (c *ConnClient) Do(req *base.Request) (*base.Response, error) { } // insert cseq - c.cseq += 1 + c.cseq++ req.Header["CSeq"] = base.HeaderValue{strconv.FormatInt(int64(c.cseq), 10)} c.nconn.SetWriteDeadline(time.Now().Add(c.d.WriteTimeout)) @@ -241,7 +241,7 @@ func (c *ConnClient) Options(u *base.URL) (*base.Response, error) { } res, err := c.Do(&base.Request{ - Method: base.OPTIONS, + Method: base.Options, URL: u, }) if err != nil { @@ -264,7 +264,7 @@ func (c *ConnClient) Options(u *base.URL) (*base.Response, error) { } for _, m := range strings.Split(pub[0], ",") { - if base.Method(m) == base.GET_PARAMETER { + if base.Method(m) == base.GetParameter { return true } } @@ -286,7 +286,7 @@ func (c *ConnClient) Describe(u *base.URL) (Tracks, *base.Response, error) { } res, err := c.Do(&base.Request{ - Method: base.DESCRIBE, + Method: base.Describe, URL: u, Header: base.Header{ "Accept": base.HeaderValue{"application/sdp"}, @@ -314,7 +314,7 @@ func (c *ConnClient) Describe(u *base.URL) (Tracks, *base.Response, error) { if err != nil { return nil, nil, err } - *c = *nc + *c = *nc //nolint:govet _, err = c.Options(u) if err != nil { @@ -342,7 +342,7 @@ func (c *ConnClient) Describe(u *base.URL) (Tracks, *base.Response, error) { } for _, t := range tracks { - t.BaseUrl = u + t.BaseURL = u } return tracks, res, nil @@ -371,7 +371,7 @@ func (c *ConnClient) Setup(mode headers.TransportMode, track *Track, return nil, fmt.Errorf("cannot read and publish at the same time") } - if c.streamUrl != nil && *track.BaseUrl != *c.streamUrl { + if c.streamURL != nil && *track.BaseURL != *c.streamURL { return nil, fmt.Errorf("cannot setup tracks with different base urls") } @@ -457,10 +457,10 @@ func (c *ConnClient) Setup(mode headers.TransportMode, track *Track, transport.ClientPorts = &[2]int{rtpPort, rtcpPort} } else { - transport.InterleavedIds = &[2]int{(track.Id * 2), (track.Id * 2) + 1} + transport.InterleavedIds = &[2]int{(track.ID * 2), (track.ID * 2) + 1} } - trackUrl, err := track.Url() + trackURL, err := track.URL() if err != nil { if proto == StreamProtocolUDP { rtpListener.close() @@ -470,8 +470,8 @@ func (c *ConnClient) Setup(mode headers.TransportMode, track *Track, } res, err := c.Do(&base.Request{ - Method: base.SETUP, - URL: trackUrl, + Method: base.Setup, + URL: trackURL, Header: base.Header{ "Transport": transport.Write(), }, @@ -539,34 +539,34 @@ func (c *ConnClient) Setup(mode headers.TransportMode, track *Track, } if mode == headers.TransportModePlay { - c.rtcpReceivers[track.Id] = rtcpreceiver.New(nil, clockRate) + c.rtcpReceivers[track.ID] = rtcpreceiver.New(nil, clockRate) if proto == StreamProtocolUDP { v := time.Now().Unix() - c.udpLastFrameTimes[track.Id] = &v + c.udpLastFrameTimes[track.ID] = &v } } else { - c.rtcpSenders[track.Id] = rtcpsender.New(clockRate) + c.rtcpSenders[track.ID] = rtcpsender.New(clockRate) } - c.streamUrl = track.BaseUrl + c.streamURL = track.BaseURL c.streamProtocol = &proto c.tracks = append(c.tracks, track) if proto == StreamProtocolUDP { - rtpListener.remoteIp = c.nconn.RemoteAddr().(*net.TCPAddr).IP + rtpListener.remoteIP = c.nconn.RemoteAddr().(*net.TCPAddr).IP rtpListener.remoteZone = c.nconn.RemoteAddr().(*net.TCPAddr).Zone rtpListener.remotePort = (*th.ServerPorts)[0] - rtpListener.trackId = track.Id + rtpListener.trackID = track.ID rtpListener.streamType = StreamTypeRtp - c.udpRtpListeners[track.Id] = rtpListener + c.udpRtpListeners[track.ID] = rtpListener - rtcpListener.remoteIp = c.nconn.RemoteAddr().(*net.TCPAddr).IP + rtcpListener.remoteIP = c.nconn.RemoteAddr().(*net.TCPAddr).IP rtcpListener.remoteZone = c.nconn.RemoteAddr().(*net.TCPAddr).Zone rtcpListener.remotePort = (*th.ServerPorts)[1] - rtcpListener.trackId = track.Id + rtcpListener.trackID = track.ID rtcpListener.streamType = StreamTypeRtcp - c.udpRtcpListeners[track.Id] = rtcpListener + c.udpRtcpListeners[track.ID] = rtcpListener } if mode == headers.TransportModePlay { @@ -593,8 +593,8 @@ func (c *ConnClient) Pause() (*base.Response, error) { <-c.backgroundDone res, err := c.Do(&base.Request{ - Method: base.PAUSE, - URL: c.streamUrl, + Method: base.Pause, + URL: c.streamURL, }) if err != nil { return nil, err diff --git a/clientconnpublish.go b/clientconnpublish.go index 94815632..72ab5ac4 100644 --- a/clientconnpublish.go +++ b/clientconnpublish.go @@ -21,8 +21,8 @@ func (c *ConnClient) Announce(u *base.URL, tracks Tracks) (*base.Response, error // set id, base url and control attribute on tracks for i, t := range tracks { - t.Id = i - t.BaseUrl = u + t.ID = i + t.BaseURL = u t.Media.Attributes = append(t.Media.Attributes, psdp.Attribute{ Key: "control", @@ -31,7 +31,7 @@ func (c *ConnClient) Announce(u *base.URL, tracks Tracks) (*base.Response, error } res, err := c.Do(&base.Request{ - Method: base.ANNOUNCE, + Method: base.Announce, URL: u, Header: base.Header{ "Content-Type": base.HeaderValue{"application/sdp"}, @@ -46,7 +46,7 @@ func (c *ConnClient) Announce(u *base.URL, tracks Tracks) (*base.Response, error return nil, fmt.Errorf("bad status code: %d (%s)", res.StatusCode, res.StatusMessage) } - c.streamUrl = u + c.streamURL = u c.state = connClientStatePreRecord return res, nil @@ -63,8 +63,8 @@ func (c *ConnClient) Record() (*base.Response, error) { } res, err := c.Do(&base.Request{ - Method: base.RECORD, - URL: c.streamUrl, + Method: base.Record, + URL: c.streamURL, }) if err != nil { return nil, err @@ -126,10 +126,10 @@ func (c *ConnClient) backgroundRecordUDP() { case <-reportTicker.C: c.publishWriteMutex.Lock() now := time.Now() - for trackId := range c.rtcpSenders { - r := c.rtcpSenders[trackId].Report(now) + for trackID := range c.rtcpSenders { + r := c.rtcpSenders[trackID].Report(now) if r != nil { - c.udpRtcpListeners[trackId].write(r) + c.udpRtcpListeners[trackID].write(r) } } c.publishWriteMutex.Unlock() @@ -161,12 +161,12 @@ func (c *ConnClient) backgroundRecordTCP() { case <-reportTicker.C: c.publishWriteMutex.Lock() now := time.Now() - for trackId := range c.rtcpSenders { - r := c.rtcpSenders[trackId].Report(now) + for trackID := range c.rtcpSenders { + r := c.rtcpSenders[trackID].Report(now) if r != nil { c.nconn.SetWriteDeadline(time.Now().Add(c.d.WriteTimeout)) frame := base.InterleavedFrame{ - TrackId: trackId, + TrackID: trackID, StreamType: StreamTypeRtcp, Content: r, } @@ -180,7 +180,7 @@ func (c *ConnClient) backgroundRecordTCP() { // WriteFrame writes a frame. // This can be called only after Record(). -func (c *ConnClient) WriteFrame(trackId int, streamType StreamType, content []byte) error { +func (c *ConnClient) WriteFrame(trackID int, streamType StreamType, content []byte) error { c.publishWriteMutex.RLock() defer c.publishWriteMutex.RUnlock() @@ -190,18 +190,18 @@ func (c *ConnClient) WriteFrame(trackId int, streamType StreamType, content []by now := time.Now() - c.rtcpSenders[trackId].ProcessFrame(now, streamType, content) + c.rtcpSenders[trackID].ProcessFrame(now, streamType, content) if *c.streamProtocol == StreamProtocolUDP { if streamType == StreamTypeRtp { - return c.udpRtpListeners[trackId].write(content) + return c.udpRtpListeners[trackID].write(content) } - return c.udpRtcpListeners[trackId].write(content) + return c.udpRtcpListeners[trackID].write(content) } c.nconn.SetWriteDeadline(now.Add(c.d.WriteTimeout)) frame := base.InterleavedFrame{ - TrackId: trackId, + TrackID: trackID, StreamType: streamType, Content: content, } diff --git a/clientconnread.go b/clientconnread.go index 1d9b0bee..f67a7fab 100644 --- a/clientconnread.go +++ b/clientconnread.go @@ -19,8 +19,8 @@ func (c *ConnClient) Play() (*base.Response, error) { } res, err := c.Do(&base.Request{ - Method: base.PLAY, - URL: c.streamUrl, + Method: base.Play, + URL: c.streamURL, }) if err != nil { return nil, err @@ -39,26 +39,26 @@ func (c *ConnClient) backgroundPlayUDP(onFrameDone chan error) { var returnError error defer func() { - for trackId := range c.udpRtpListeners { - c.udpRtpListeners[trackId].stop() - c.udpRtcpListeners[trackId].stop() + for trackID := range c.udpRtpListeners { + c.udpRtpListeners[trackID].stop() + c.udpRtcpListeners[trackID].stop() } onFrameDone <- returnError }() // open the firewall by sending packets to the counterpart - for trackId := range c.udpRtpListeners { - c.udpRtpListeners[trackId].write( + for trackID := range c.udpRtpListeners { + c.udpRtpListeners[trackID].write( []byte{0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}) - c.udpRtcpListeners[trackId].write( + c.udpRtcpListeners[trackID].write( []byte{0x80, 0xc9, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00}) } - for trackId := range c.udpRtpListeners { - c.udpRtpListeners[trackId].start() - c.udpRtcpListeners[trackId].start() + for trackID := range c.udpRtpListeners { + c.udpRtpListeners[trackID].start() + c.udpRtcpListeners[trackID].start() } // disable deadline @@ -95,9 +95,9 @@ func (c *ConnClient) backgroundPlayUDP(onFrameDone chan error) { case <-reportTicker.C: now := time.Now() - for trackId := range c.rtcpReceivers { - r := c.rtcpReceivers[trackId].Report(now) - c.udpRtcpListeners[trackId].write(r) + for trackID := range c.rtcpReceivers { + r := c.rtcpReceivers[trackID].Report(now) + c.udpRtcpListeners[trackID].write(r) } case <-keepaliveTicker.C: @@ -105,12 +105,12 @@ func (c *ConnClient) backgroundPlayUDP(onFrameDone chan error) { Method: func() base.Method { // the vlc integrated rtsp server requires GET_PARAMETER if c.getParameterSupported { - return base.GET_PARAMETER + return base.GetParameter } - return base.OPTIONS + return base.Options }(), // use the stream path, otherwise some cameras do not reply - URL: c.streamUrl, + URL: c.streamURL, SkipResponse: true, }) if err != nil { @@ -162,9 +162,9 @@ func (c *ConnClient) backgroundPlayTCP(onFrameDone chan error) { return } - c.rtcpReceivers[frame.TrackId].ProcessFrame(time.Now(), frame.StreamType, frame.Content) + c.rtcpReceivers[frame.TrackID].ProcessFrame(time.Now(), frame.StreamType, frame.Content) - c.readCB(frame.TrackId, frame.StreamType, frame.Content) + c.readCB(frame.TrackID, frame.StreamType, frame.Content) } }() @@ -190,11 +190,11 @@ func (c *ConnClient) backgroundPlayTCP(onFrameDone chan error) { case <-reportTicker.C: now := time.Now() - for trackId := range c.rtcpReceivers { - r := c.rtcpReceivers[trackId].Report(now) + for trackID := range c.rtcpReceivers { + r := c.rtcpReceivers[trackID].Report(now) c.nconn.SetWriteDeadline(time.Now().Add(c.d.WriteTimeout)) frame := base.InterleavedFrame{ - TrackId: trackId, + TrackID: trackID, StreamType: StreamTypeRtcp, Content: r, } diff --git a/clientconnudpl.go b/clientconnudpl.go index 3ee042bd..b4803f8c 100644 --- a/clientconnudpl.go +++ b/clientconnudpl.go @@ -19,11 +19,11 @@ const ( type connClientUDPListener struct { c *ConnClient pc net.PacketConn - remoteIp net.IP + remoteIP net.IP remoteZone string remotePort int udpFrameBuffer *multibuffer.MultiBuffer - trackId int + trackID int streamType StreamType running bool @@ -79,22 +79,22 @@ func (l *connClientUDPListener) run() { uaddr := addr.(*net.UDPAddr) - if !l.remoteIp.Equal(uaddr.IP) || l.remotePort != uaddr.Port { + if !l.remoteIP.Equal(uaddr.IP) || l.remotePort != uaddr.Port { continue } now := time.Now() - atomic.StoreInt64(l.c.udpLastFrameTimes[l.trackId], now.Unix()) - l.c.rtcpReceivers[l.trackId].ProcessFrame(now, l.streamType, buf[:n]) + atomic.StoreInt64(l.c.udpLastFrameTimes[l.trackID], now.Unix()) + l.c.rtcpReceivers[l.trackID].ProcessFrame(now, l.streamType, buf[:n]) - l.c.readCB(l.trackId, l.streamType, buf[:n]) + l.c.readCB(l.trackID, l.streamType, buf[:n]) } } func (l *connClientUDPListener) write(buf []byte) error { l.pc.SetWriteDeadline(time.Now().Add(l.c.d.WriteTimeout)) _, err := l.pc.WriteTo(buf, &net.UDPAddr{ - IP: l.remoteIp, + IP: l.remoteIP, Zone: l.remoteZone, Port: l.remotePort, }) diff --git a/clientdialer_test.go b/clientdialer_test.go index e201a4c3..faf4dc8a 100644 --- a/clientdialer_test.go +++ b/clientdialer_test.go @@ -322,14 +322,14 @@ func TestDialPublishSerial(t *testing.T) { buf := make([]byte, 2048) n, _, err := pc.ReadFrom(buf) require.NoError(t, err) - err = conn.WriteFrame(track.Id, StreamTypeRtp, buf[:n]) + err = conn.WriteFrame(track.ID, StreamTypeRtp, buf[:n]) require.NoError(t, err) conn.Close() n, _, err = pc.ReadFrom(buf) require.NoError(t, err) - err = conn.WriteFrame(track.Id, StreamTypeRtp, buf[:n]) + err = conn.WriteFrame(track.ID, StreamTypeRtp, buf[:n]) require.Error(t, err) }) } @@ -420,7 +420,7 @@ func TestDialPublishParallel(t *testing.T) { break } - err = conn.WriteFrame(track.Id, StreamTypeRtp, buf[:n]) + err = conn.WriteFrame(track.ID, StreamTypeRtp, buf[:n]) if err != nil { break } @@ -498,7 +498,7 @@ func TestDialPublishPauseSerial(t *testing.T) { n, _, err := pc.ReadFrom(buf) require.NoError(t, err) - err = conn.WriteFrame(track.Id, StreamTypeRtp, buf[:n]) + err = conn.WriteFrame(track.ID, StreamTypeRtp, buf[:n]) require.NoError(t, err) _, err = conn.Pause() @@ -506,7 +506,7 @@ func TestDialPublishPauseSerial(t *testing.T) { n, _, err = pc.ReadFrom(buf) require.NoError(t, err) - err = conn.WriteFrame(track.Id, StreamTypeRtp, buf[:n]) + err = conn.WriteFrame(track.ID, StreamTypeRtp, buf[:n]) require.Error(t, err) _, err = conn.Record() @@ -514,7 +514,7 @@ func TestDialPublishPauseSerial(t *testing.T) { n, _, err = pc.ReadFrom(buf) require.NoError(t, err) - err = conn.WriteFrame(track.Id, StreamTypeRtp, buf[:n]) + err = conn.WriteFrame(track.ID, StreamTypeRtp, buf[:n]) require.NoError(t, err) }) } @@ -574,7 +574,7 @@ func TestDialPublishPauseParallel(t *testing.T) { n, _, err := pc.ReadFrom(buf) require.NoError(t, err) - err = conn.WriteFrame(track.Id, StreamTypeRtp, buf[:n]) + err = conn.WriteFrame(track.ID, StreamTypeRtp, buf[:n]) if err != nil { break } diff --git a/connserver.go b/connserver.go index 892d70c8..702a5cd3 100644 --- a/connserver.go +++ b/connserver.go @@ -105,9 +105,9 @@ func (s *ConnServer) WriteResponse(res *base.Response) error { } // WriteFrameTCP writes an InterleavedFrame. -func (s *ConnServer) WriteFrameTCP(trackId int, streamType StreamType, content []byte) error { +func (s *ConnServer) WriteFrameTCP(trackID int, streamType StreamType, content []byte) error { frame := base.InterleavedFrame{ - TrackId: trackId, + TrackID: trackID, StreamType: streamType, Content: content, } diff --git a/examples/client-publish-options.go b/examples/client-publish-options.go index c4d0a0d2..46deee49 100644 --- a/examples/client-publish-options.go +++ b/examples/client-publish-options.go @@ -70,7 +70,7 @@ func main() { } // write track frames - err = conn.WriteFrame(track.Id, gortsplib.StreamTypeRtp, buf[:n]) + err = conn.WriteFrame(track.ID, gortsplib.StreamTypeRtp, buf[:n]) if err != nil { panic(err) } diff --git a/examples/client-publish-pause.go b/examples/client-publish-pause.go index b7ecc0ef..ebc2a58d 100644 --- a/examples/client-publish-pause.go +++ b/examples/client-publish-pause.go @@ -66,7 +66,7 @@ func main() { } // write track frames - err = conn.WriteFrame(track.Id, gortsplib.StreamTypeRtp, buf[:n]) + err = conn.WriteFrame(track.ID, gortsplib.StreamTypeRtp, buf[:n]) if err != nil { break } diff --git a/examples/client-publish.go b/examples/client-publish.go index 5c48c0e5..697343a3 100644 --- a/examples/client-publish.go +++ b/examples/client-publish.go @@ -58,7 +58,7 @@ func main() { } // write track frames - err = conn.WriteFrame(track.Id, gortsplib.StreamTypeRtp, buf[:n]) + err = conn.WriteFrame(track.ID, gortsplib.StreamTypeRtp, buf[:n]) if err != nil { panic(err) } diff --git a/pkg/auth/package_test.go b/pkg/auth/package_test.go index 64e742eb..29144420 100644 --- a/pkg/auth/package_test.go +++ b/pkg/auth/package_test.go @@ -36,10 +36,10 @@ func TestAuthMethods(t *testing.T) { ac, err := NewClient(wwwAuthenticate, url.UserPassword("testuser", "testpass")) require.NoError(t, err) - authorization := ac.GenerateHeader(base.ANNOUNCE, + authorization := ac.GenerateHeader(base.Announce, base.MustParseURL("rtsp://myhost/mypath")) - err = authServer.ValidateHeader(authorization, base.ANNOUNCE, + err = authServer.ValidateHeader(authorization, base.Announce, base.MustParseURL("rtsp://myhost/mypath")) require.NoError(t, err) }) @@ -53,11 +53,11 @@ func TestAuthVLC(t *testing.T) { }{ { "rtsp://myhost/mypath/", - "rtsp://myhost/mypath/trackId=0", + "rtsp://myhost/mypath/trackID=0", }, { "rtsp://myhost/mypath/test?testing/", - "rtsp://myhost/mypath/test?testing/trackId=0", + "rtsp://myhost/mypath/test?testing/trackID=0", }, } { authServer := NewServer("testuser", "testpass", @@ -66,10 +66,10 @@ func TestAuthVLC(t *testing.T) { ac, err := NewClient(wwwAuthenticate, url.UserPassword("testuser", "testpass")) require.NoError(t, err) - authorization := ac.GenerateHeader(base.ANNOUNCE, + authorization := ac.GenerateHeader(base.Announce, base.MustParseURL(ca.clientURL)) - err = authServer.ValidateHeader(authorization, base.ANNOUNCE, + err = authServer.ValidateHeader(authorization, base.Announce, base.MustParseURL(ca.serverURL)) require.NoError(t, err) } diff --git a/pkg/base/interleavedframe.go b/pkg/base/interleavedframe.go index 0ed069b5..21b00baf 100644 --- a/pkg/base/interleavedframe.go +++ b/pkg/base/interleavedframe.go @@ -61,7 +61,7 @@ func ReadInterleavedFrameOrResponse(frame *InterleavedFrame, res *Response, br * // within RTSP/TCP connections. It is used to send and receive RTP and RTCP packets with TCP. type InterleavedFrame struct { // track id - TrackId int + TrackID int // stream type StreamType StreamType @@ -88,9 +88,9 @@ func (f *InterleavedFrame) Read(br *bufio.Reader) error { framelen, len(f.Content)) } - // convert channel into TrackId and StreamType + // convert channel into TrackID and StreamType channel := header[1] - f.TrackId, f.StreamType = func() (int, StreamType) { + f.TrackID, f.StreamType = func() (int, StreamType) { if (channel % 2) == 0 { return int(channel / 2), StreamTypeRtp } @@ -108,12 +108,12 @@ func (f *InterleavedFrame) Read(br *bufio.Reader) error { // Write writes an InterleavedFrame into a buffered writer. func (f InterleavedFrame) Write(bw *bufio.Writer) error { - // convert TrackId and StreamType into channel + // convert TrackID and StreamType into channel channel := func() uint8 { if f.StreamType == StreamTypeRtp { - return uint8(f.TrackId * 2) + return uint8(f.TrackID * 2) } - return uint8((f.TrackId * 2) + 1) + return uint8((f.TrackID * 2) + 1) }() _, err := bw.Write([]byte{0x24, channel}) diff --git a/pkg/base/request.go b/pkg/base/request.go index 20bcb6d1..4d7cf47a 100644 --- a/pkg/base/request.go +++ b/pkg/base/request.go @@ -19,18 +19,18 @@ type Method string // standard methods const ( - ANNOUNCE Method = "ANNOUNCE" - DESCRIBE Method = "DESCRIBE" - GET_PARAMETER Method = "GET_PARAMETER" - OPTIONS Method = "OPTIONS" - PAUSE Method = "PAUSE" - PLAY Method = "PLAY" - PLAY_NOTIFY Method = "PLAY_NOTIFY" - RECORD Method = "RECORD" - REDIRECT Method = "REDIRECT" - SETUP Method = "SETUP" - SET_PARAMETER Method = "SET_PARAMETER" - TEARDOWN Method = "TEARDOWN" + Announce Method = "ANNOUNCE" + Describe Method = "DESCRIBE" + GetParameter Method = "GET_PARAMETER" + Options Method = "OPTIONS" + Pause Method = "PAUSE" + Play Method = "PLAY" + PlayNotify Method = "PLAY_NOTIFY" + Record Method = "RECORD" + Redirect Method = "REDIRECT" + Setup Method = "SETUP" + SetParameter Method = "SET_PARAMETER" + Teardown Method = "TEARDOWN" ) // Request is a RTSP request. @@ -68,15 +68,15 @@ func (req *Request) Read(rb *bufio.Reader) error { if err != nil { return err } - rawUrl := string(byts[:len(byts)-1]) + rawURL := string(byts[:len(byts)-1]) - if rawUrl == "" { + if rawURL == "" { return fmt.Errorf("empty url") } - ur, err := ParseURL(rawUrl) + ur, err := ParseURL(rawURL) if err != nil { - return fmt.Errorf("unable to parse url (%v)", rawUrl) + return fmt.Errorf("unable to parse url (%v)", rawURL) } req.URL = ur diff --git a/pkg/multibuffer/multibuffer.go b/pkg/multibuffer/multibuffer.go index f9770e6c..e92d7185 100644 --- a/pkg/multibuffer/multibuffer.go +++ b/pkg/multibuffer/multibuffer.go @@ -25,7 +25,7 @@ func New(count int, size int) *MultiBuffer { // Next gets the current buffer and sets the next buffer as the current one. func (mb *MultiBuffer) Next() []byte { ret := mb.buffers[mb.cur] - mb.cur += 1 + mb.cur++ if mb.cur >= mb.count { mb.cur = 0 } diff --git a/pkg/rtcpreceiver/rtcpreceiver.go b/pkg/rtcpreceiver/rtcpreceiver.go index 1c023ec8..b56c8291 100644 --- a/pkg/rtcpreceiver/rtcpreceiver.go +++ b/pkg/rtcpreceiver/rtcpreceiver.go @@ -74,7 +74,7 @@ func (rr *RtcpReceiver) ProcessFrame(ts time.Time, streamType base.StreamType, b if diff > 0 || diff < -0x0FFF { // overflow if diff < -0x0FFF { - rr.sequenceNumberCycles += 1 + rr.sequenceNumberCycles++ } // detect lost frames diff --git a/pkg/rtpaac/encoder.go b/pkg/rtpaac/encoder.go index aebded11..35b1a8b1 100644 --- a/pkg/rtpaac/encoder.go +++ b/pkg/rtpaac/encoder.go @@ -51,7 +51,7 @@ func (e *Encoder) Write(ts time.Duration, data []byte) ([][]byte, error) { // 13 bits payload size // 3 bits AU-Index(-delta) header := make([]byte, 2) - binary.BigEndian.PutUint16(header, (uint16(len(data))<<3)|0) + binary.BigEndian.PutUint16(header, uint16(len(data))<<3) payload := append([]byte{0x00, 0x10}, header...) payload = append(payload, data...) diff --git a/pkg/sdp/sdp_test.go b/pkg/sdp/sdp_test.go index 97255aa7..6181264e 100644 --- a/pkg/sdp/sdp_test.go +++ b/pkg/sdp/sdp_test.go @@ -1,3 +1,4 @@ +//nolint:govet package sdp import ( diff --git a/track.go b/track.go index 2f0d4f7f..1843224b 100644 --- a/track.go +++ b/track.go @@ -17,10 +17,10 @@ import ( // Track is a track available in a certain URL. type Track struct { // base url - BaseUrl *base.URL + BaseURL *base.URL // id - Id int + ID int // codec and info in SDP format Media *psdp.MediaDescription @@ -30,7 +30,7 @@ type Track struct { func NewTrackH264(payloadType uint8, sps []byte, pps []byte) (*Track, error) { spropParameterSets := base64.StdEncoding.EncodeToString(sps) + "," + base64.StdEncoding.EncodeToString(pps) - profileLevelId := strings.ToUpper(hex.EncodeToString(sps[1:4])) + profileLevelID := strings.ToUpper(hex.EncodeToString(sps[1:4])) typ := strconv.FormatInt(int64(payloadType), 10) @@ -50,7 +50,7 @@ func NewTrackH264(payloadType uint8, sps []byte, pps []byte) (*Track, error) { Key: "fmtp", Value: typ + " packetization-mode=1; " + "sprop-parameter-sets=" + spropParameterSets + "; " + - "profile-level-id=" + profileLevelId, + "profile-level-id=" + profileLevelID, }, }, }, @@ -162,8 +162,8 @@ func (t *Track) ClockRate() (int, error) { } // Url returns the track url. -func (t *Track) Url() (*base.URL, error) { - if t.BaseUrl == nil { +func (t *Track) URL() (*base.URL, error) { + if t.BaseURL == nil { return nil, fmt.Errorf("empty base url") } @@ -178,7 +178,7 @@ func (t *Track) Url() (*base.URL, error) { // no control attribute, use base URL if control == "" { - return t.BaseUrl, nil + return t.BaseURL, nil } // control attribute contains an absolute path @@ -189,13 +189,13 @@ func (t *Track) Url() (*base.URL, error) { } // copy host and credentials - ur.Host = t.BaseUrl.Host - ur.User = t.BaseUrl.User + ur.Host = t.BaseURL.Host + ur.User = t.BaseURL.User return ur, nil } // control attribute contains a relative control attribute - ur := t.BaseUrl.Clone() + ur := t.BaseURL.Clone() ur.AddControlAttribute(control) return ur, nil } @@ -214,7 +214,7 @@ func ReadTracks(byts []byte) (Tracks, error) { ts := make(Tracks, len(desc.MediaDescriptions)) for i, media := range desc.MediaDescriptions { ts[i] = &Track{ - Id: i, + ID: i, Media: media, } } @@ -239,7 +239,7 @@ func (ts Tracks) Write() []byte { Address: &psdp.Address{Address: "0.0.0.0"}, }, TimeDescriptions: []psdp.TimeDescription{ - {Timing: psdp.Timing{0, 0}}, + {Timing: psdp.Timing{0, 0}}, //nolint:govet }, }