diff --git a/.golangci.yml b/.golangci.yml index 9ab04e06..5c7573c1 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -9,6 +9,7 @@ linters: - gofumpt - golint - misspell + - lll - prealloc - unconvert disable: diff --git a/internal/conf/path.go b/internal/conf/path.go index 95d764e5..570ab0aa 100644 --- a/internal/conf/path.go +++ b/internal/conf/path.go @@ -75,7 +75,7 @@ type PathConf struct { SourceAnyPortEnable bool `yaml:"sourceAnyPortEnable" json:"sourceAnyPortEnable"` SourceFingerprint string `yaml:"sourceFingerprint" json:"sourceFingerprint"` SourceOnDemand bool `yaml:"sourceOnDemand" json:"sourceOnDemand"` - SourceOnDemandStartTimeout time.Duration `yaml:"sourceOnDemandStartTimeout" json:"sourceOnDemandStartTimeout"` + SourceOnDemandStartTimeout time.Duration `yaml:"sourceOnDemandStartTimeout" json:"sourceOnDemandStartTimeout"` //nolint:lll SourceOnDemandCloseAfter time.Duration `yaml:"sourceOnDemandCloseAfter" json:"sourceOnDemandCloseAfter"` SourceRedirect string `yaml:"sourceRedirect" json:"sourceRedirect"` DisablePublisherOverride bool `yaml:"disablePublisherOverride" json:"disablePublisherOverride"` @@ -272,7 +272,8 @@ func (pconf *PathConf) checkAndFillMissing(name string) error { } if pconf.PublishPass != "" { if pconf.Source != "publisher" { - return fmt.Errorf("'publishPass' is useless when source is not 'publisher', since the stream is not provided by a publisher, but by a fixed source") + return fmt.Errorf("'publishPass' is useless when source is not 'publisher', since " + + "the stream is not provided by a publisher, but by a fixed source") } if !strings.HasPrefix(pconf.PublishPass, "sha256:") && !reUserPass.MatchString(pconf.PublishPass) { @@ -289,7 +290,8 @@ func (pconf *PathConf) checkAndFillMissing(name string) error { } if pconf.Source != "publisher" { - return nil, fmt.Errorf("'publishIPs' is useless when source is not 'publisher', since the stream is not provided by a publisher, but by a fixed source") + return nil, fmt.Errorf("'publishIPs' is useless when source is not 'publisher', since " + + "the stream is not provided by a publisher, but by a fixed source") } return parseIPCidrList(pconf.PublishIPs) @@ -326,7 +328,8 @@ func (pconf *PathConf) checkAndFillMissing(name string) error { } if pconf.RunOnPublish != "" && pconf.Source != "publisher" { - return fmt.Errorf("'runOnPublish' is useless when source is not 'publisher', since the stream is not provided by a publisher, but by a fixed source") + return fmt.Errorf("'runOnPublish' is useless when source is not 'publisher', since " + + "the stream is not provided by a publisher, but by a fixed source") } if pconf.RunOnDemand != "" && pconf.Source != "publisher" { diff --git a/internal/core/api_test.go b/internal/core/api_test.go index 636cc2a9..be78d319 100644 --- a/internal/core/api_test.go +++ b/internal/core/api_test.go @@ -96,7 +96,8 @@ func TestAPIConfigPathsAdd(t *testing.T) { var out map[string]interface{} err = httpRequest(http.MethodGet, "http://localhost:9997/v1/config/get", nil, &out) require.NoError(t, err) - require.Equal(t, "rtsp://127.0.0.1:9999/mypath", out["paths"].(map[string]interface{})["mypath"].(map[string]interface{})["source"]) + require.Equal(t, "rtsp://127.0.0.1:9999/mypath", + out["paths"].(map[string]interface{})["mypath"].(map[string]interface{})["source"]) } func TestAPIConfigPathsEdit(t *testing.T) { @@ -179,7 +180,8 @@ func TestAPIPathsList(t *testing.T) { _, ok = out.Items["mypath"] require.Equal(t, true, ok) - track, err := gortsplib.NewTrackH264(96, &gortsplib.TrackConfigH264{SPS: []byte{0x01, 0x02, 0x03, 0x04}, PPS: []byte{0x01, 0x02, 0x03, 0x04}}) + track, err := gortsplib.NewTrackH264(96, + &gortsplib.TrackConfigH264{SPS: []byte{0x01, 0x02, 0x03, 0x04}, PPS: []byte{0x01, 0x02, 0x03, 0x04}}) require.NoError(t, err) func() { @@ -227,7 +229,8 @@ func TestAPIList(t *testing.T) { require.Equal(t, true, ok) defer p.close() - track, err := gortsplib.NewTrackH264(96, &gortsplib.TrackConfigH264{SPS: []byte{0x01, 0x02, 0x03, 0x04}, PPS: []byte{0x01, 0x02, 0x03, 0x04}}) + track, err := gortsplib.NewTrackH264(96, + &gortsplib.TrackConfigH264{SPS: []byte{0x01, 0x02, 0x03, 0x04}, PPS: []byte{0x01, 0x02, 0x03, 0x04}}) require.NoError(t, err) switch ca { @@ -308,7 +311,8 @@ func TestAPIKick(t *testing.T) { require.Equal(t, true, ok) defer p.close() - track, err := gortsplib.NewTrackH264(96, &gortsplib.TrackConfigH264{SPS: []byte{0x01, 0x02, 0x03, 0x04}, PPS: []byte{0x01, 0x02, 0x03, 0x04}}) + track, err := gortsplib.NewTrackH264(96, + &gortsplib.TrackConfigH264{SPS: []byte{0x01, 0x02, 0x03, 0x04}, PPS: []byte{0x01, 0x02, 0x03, 0x04}}) require.NoError(t, err) switch ca { diff --git a/internal/core/core.go b/internal/core/core.go index af9221bd..44b6d57e 100644 --- a/internal/core/core.go +++ b/internal/core/core.go @@ -49,7 +49,8 @@ func New(args []string) (*Core, bool) { "rtsp-simple-server "+version+"\n\nRTSP server.") argVersion := k.Flag("version", "print version").Bool() - argConfPath := k.Arg("confpath", "path to a config file. The default is rtsp-simple-server.yml.").Default("rtsp-simple-server.yml").String() + argConfPath := k.Arg("confpath", "path to a config file. The default is rtsp-simple-server.yml."). + Default("rtsp-simple-server.yml").String() kingpin.MustParse(k.Parse(args)) diff --git a/internal/core/core_test.go b/internal/core/core_test.go index eced0b5e..1380a67d 100644 --- a/internal/core/core_test.go +++ b/internal/core/core_test.go @@ -153,7 +153,8 @@ func TestCoreHotReloading(t *testing.T) { err := ioutil.WriteFile(confPath, []byte("paths:\n"+ " test1:\n"+ - " runOnDemand: ffmpeg -hide_banner -loglevel error -re -i ../../testimages/ffmpeg/emptyvideo.mkv -c copy -f rtsp rtsp://localhost:$RTSP_PORT/$RTSP_PATH\n"+ + " runOnDemand: ffmpeg -hide_banner -loglevel error -re "+ + "-i ../../testimages/ffmpeg/emptyvideo.mkv -c copy -f rtsp rtsp://localhost:$RTSP_PORT/$RTSP_PATH\n"+ " test3:\n"+ " runOnInit: echo aaa\n"+ " test4:\n"+ @@ -178,7 +179,8 @@ func TestCoreHotReloading(t *testing.T) { err = ioutil.WriteFile(confPath, []byte("paths:\n"+ " test2:\n"+ - " runOnDemand: ffmpeg -hide_banner -loglevel error -re -i ../../testimages/ffmpeg/emptyvideo.mkv -c copy -f rtsp rtsp://localhost:$RTSP_PORT/$RTSP_PATH\n"+ + " runOnDemand: ffmpeg -hide_banner -loglevel error -re "+ + "-i ../../testimages/ffmpeg/emptyvideo.mkv -c copy -f rtsp rtsp://localhost:$RTSP_PORT/$RTSP_PATH\n"+ " test3:\n"+ " test4:\n"+ " runOnInit: echo bbb\n"), diff --git a/internal/core/metrics_test.go b/internal/core/metrics_test.go index ae7b5121..3c35b4ab 100644 --- a/internal/core/metrics_test.go +++ b/internal/core/metrics_test.go @@ -27,7 +27,8 @@ func TestMetrics(t *testing.T) { require.Equal(t, true, ok) defer p.close() - track, err := gortsplib.NewTrackH264(96, &gortsplib.TrackConfigH264{SPS: []byte{0x01, 0x02, 0x03, 0x04}, PPS: []byte{0x01, 0x02, 0x03, 0x04}}) + track, err := gortsplib.NewTrackH264(96, + &gortsplib.TrackConfigH264{SPS: []byte{0x01, 0x02, 0x03, 0x04}, PPS: []byte{0x01, 0x02, 0x03, 0x04}}) require.NoError(t, err) source, err := gortsplib.DialPublish("rtsp://localhost:8554/mypath", diff --git a/internal/core/rtsp_conn.go b/internal/core/rtsp_conn.go index 80acf74d..01b5f2ff 100644 --- a/internal/core/rtsp_conn.go +++ b/internal/core/rtsp_conn.go @@ -186,7 +186,8 @@ func (c *rtspConn) OnResponse(res *base.Response) { } // OnDescribe is called by rtspServer. -func (c *rtspConn) OnDescribe(ctx *gortsplib.ServerHandlerOnDescribeCtx) (*base.Response, *gortsplib.ServerStream, error) { +func (c *rtspConn) OnDescribe(ctx *gortsplib.ServerHandlerOnDescribeCtx, +) (*base.Response, *gortsplib.ServerStream, error) { res := c.pathManager.OnDescribe(pathDescribeReq{ PathName: ctx.Path, URL: ctx.Req.URL, diff --git a/internal/core/rtsp_server.go b/internal/core/rtsp_server.go index a5354bb0..4d241362 100644 --- a/internal/core/rtsp_server.go +++ b/internal/core/rtsp_server.go @@ -303,7 +303,8 @@ func (s *rtspServer) OnSessionClose(ctx *gortsplib.ServerHandlerOnSessionCloseCt } // OnDescribe implements gortsplib.ServerHandlerOnDescribe. -func (s *rtspServer) OnDescribe(ctx *gortsplib.ServerHandlerOnDescribeCtx) (*base.Response, *gortsplib.ServerStream, error) { +func (s *rtspServer) OnDescribe(ctx *gortsplib.ServerHandlerOnDescribeCtx, +) (*base.Response, *gortsplib.ServerStream, error) { s.mutex.RLock() c := s.conns[ctx.Conn] s.mutex.RUnlock() diff --git a/internal/core/rtsp_server_test.go b/internal/core/rtsp_server_test.go index afe6c3a4..72dc1d75 100644 --- a/internal/core/rtsp_server_test.go +++ b/internal/core/rtsp_server_test.go @@ -175,7 +175,8 @@ func TestRTSPServerPublishRead(t *testing.T) { }() cnt2, err := newContainer("gstreamer", "read", []string{ - "rtspsrc location=" + proto + "://127.0.0.1:" + port + "/teststream protocols=" + ps + " tls-validation-flags=0 latency=0 " + + "rtspsrc location=" + proto + "://127.0.0.1:" + port + "/teststream protocols=" + ps + + " tls-validation-flags=0 latency=0 " + "! application/x-rtp,media=video ! decodebin ! exitafterframe ! fakesink", }) require.NoError(t, err) @@ -354,7 +355,8 @@ func TestRTSPServerAuthFail(t *testing.T) { require.Equal(t, true, ok) defer p.close() - track, err := gortsplib.NewTrackH264(96, &gortsplib.TrackConfigH264{SPS: []byte{0x01, 0x02, 0x03, 0x04}, PPS: []byte{0x01, 0x02, 0x03, 0x04}}) + track, err := gortsplib.NewTrackH264(96, + &gortsplib.TrackConfigH264{SPS: []byte{0x01, 0x02, 0x03, 0x04}, PPS: []byte{0x01, 0x02, 0x03, 0x04}}) require.NoError(t, err) _, err = gortsplib.DialPublish( @@ -412,7 +414,8 @@ func TestRTSPServerAuthFail(t *testing.T) { require.Equal(t, true, ok) defer p.close() - track, err := gortsplib.NewTrackH264(96, &gortsplib.TrackConfigH264{SPS: []byte{0x01, 0x02, 0x03, 0x04}, PPS: []byte{0x01, 0x02, 0x03, 0x04}}) + track, err := gortsplib.NewTrackH264(96, + &gortsplib.TrackConfigH264{SPS: []byte{0x01, 0x02, 0x03, 0x04}, PPS: []byte{0x01, 0x02, 0x03, 0x04}}) require.NoError(t, err) _, err = gortsplib.DialPublish( @@ -477,7 +480,8 @@ func TestRTSPServerPublisherOverride(t *testing.T) { require.Equal(t, true, ok) defer p.close() - track, err := gortsplib.NewTrackH264(96, &gortsplib.TrackConfigH264{SPS: []byte{0x01, 0x02, 0x03, 0x04}, PPS: []byte{0x01, 0x02, 0x03, 0x04}}) + track, err := gortsplib.NewTrackH264(96, + &gortsplib.TrackConfigH264{SPS: []byte{0x01, 0x02, 0x03, 0x04}, PPS: []byte{0x01, 0x02, 0x03, 0x04}}) require.NoError(t, err) s1, err := gortsplib.DialPublish("rtsp://localhost:8554/teststream", @@ -544,7 +548,8 @@ func TestRTSPServerNonCompliantFrameSize(t *testing.T) { require.Equal(t, true, ok) defer p.close() - track, err := gortsplib.NewTrackH264(96, &gortsplib.TrackConfigH264{SPS: []byte{0x01, 0x02, 0x03, 0x04}, PPS: []byte{0x01, 0x02, 0x03, 0x04}}) + track, err := gortsplib.NewTrackH264(96, + &gortsplib.TrackConfigH264{SPS: []byte{0x01, 0x02, 0x03, 0x04}, PPS: []byte{0x01, 0x02, 0x03, 0x04}}) require.NoError(t, err) client := &gortsplib.Client{ @@ -594,7 +599,8 @@ func TestRTSPServerNonCompliantFrameSize(t *testing.T) { require.Equal(t, true, ok) defer p1.close() - track, err := gortsplib.NewTrackH264(96, &gortsplib.TrackConfigH264{SPS: []byte{0x01, 0x02, 0x03, 0x04}, PPS: []byte{0x01, 0x02, 0x03, 0x04}}) + track, err := gortsplib.NewTrackH264(96, + &gortsplib.TrackConfigH264{SPS: []byte{0x01, 0x02, 0x03, 0x04}, PPS: []byte{0x01, 0x02, 0x03, 0x04}}) require.NoError(t, err) client := &gortsplib.Client{ @@ -742,7 +748,8 @@ func TestRTSPServerRunOnDemand(t *testing.T) { doneFile := filepath.Join(os.TempDir(), "ondemand_done") onDemandFile, err := writeTempFile([]byte(fmt.Sprintf(`#!/bin/sh trap 'touch %s; [ -z "$(jobs -p)" ] || kill $(jobs -p)' QUIT -ffmpeg -hide_banner -loglevel error -re -i ../../testimages/ffmpeg/emptyvideo.mkv -c copy -f rtsp rtsp://localhost:$RTSP_PORT/$RTSP_PATH & +ffmpeg -hide_banner -loglevel error -re `+ + `-i ../../testimages/ffmpeg/emptyvideo.mkv -c copy -f rtsp rtsp://localhost:$RTSP_PORT/$RTSP_PATH & wait `, doneFile))) require.NoError(t, err) diff --git a/internal/core/rtsp_session.go b/internal/core/rtsp_session.go index 70930acd..4c561810 100644 --- a/internal/core/rtsp_session.go +++ b/internal/core/rtsp_session.go @@ -170,7 +170,8 @@ func (s *rtspSession) OnAnnounce(c *rtspConn, ctx *gortsplib.ServerHandlerOnAnno } // OnSetup is called by rtspServer. -func (s *rtspSession) OnSetup(c *rtspConn, ctx *gortsplib.ServerHandlerOnSetupCtx) (*base.Response, *gortsplib.ServerStream, error) { +func (s *rtspSession) OnSetup(c *rtspConn, ctx *gortsplib.ServerHandlerOnSetupCtx, +) (*base.Response, *gortsplib.ServerStream, error) { if ctx.Transport.Protocol == base.StreamProtocolUDP { if _, ok := s.protocols[conf.ProtocolUDP]; !ok { return &base.Response{ diff --git a/internal/core/rtsp_source_test.go b/internal/core/rtsp_source_test.go index bba79ace..15900b12 100644 --- a/internal/core/rtsp_source_test.go +++ b/internal/core/rtsp_source_test.go @@ -21,7 +21,8 @@ type testServer struct { done chan struct{} } -func (sh *testServer) OnDescribe(ctx *gortsplib.ServerHandlerOnDescribeCtx) (*base.Response, *gortsplib.ServerStream, error) { +func (sh *testServer) OnDescribe(ctx *gortsplib.ServerHandlerOnDescribeCtx, +) (*base.Response, *gortsplib.ServerStream, error) { if sh.authValidator == nil { sh.authValidator = auth.NewValidator(sh.user, sh.pass, nil) } @@ -36,7 +37,8 @@ func (sh *testServer) OnDescribe(ctx *gortsplib.ServerHandlerOnDescribeCtx) (*ba }, nil, nil } - track, _ := gortsplib.NewTrackH264(96, &gortsplib.TrackConfigH264{SPS: []byte{0x01, 0x02, 0x03, 0x04}, PPS: []byte{0x05, 0x06}}) + track, _ := gortsplib.NewTrackH264(96, + &gortsplib.TrackConfigH264{SPS: []byte{0x01, 0x02, 0x03, 0x04}, PPS: []byte{0x05, 0x06}}) sh.stream = gortsplib.NewServerStream(gortsplib.Tracks{track}) return &base.Response{ diff --git a/internal/hls/muxer_test.go b/internal/hls/muxer_test.go index 51069e87..9e407e66 100644 --- a/internal/hls/muxer_test.go +++ b/internal/hls/muxer_test.go @@ -17,10 +17,12 @@ func checkTSPacket(t *testing.T, byts []byte, pid int, afc int) { } func TestMuxer(t *testing.T) { - videoTrack, err := gortsplib.NewTrackH264(96, &gortsplib.TrackConfigH264{SPS: []byte{0x07, 0x01, 0x02, 0x03}, PPS: []byte{0x08}}) + videoTrack, err := gortsplib.NewTrackH264(96, + &gortsplib.TrackConfigH264{SPS: []byte{0x07, 0x01, 0x02, 0x03}, PPS: []byte{0x08}}) require.NoError(t, err) - audioTrack, err := gortsplib.NewTrackAAC(97, &gortsplib.TrackConfigAAC{Type: 2, SampleRate: 44100, ChannelCount: 2}) + audioTrack, err := gortsplib.NewTrackAAC(97, + &gortsplib.TrackConfigAAC{Type: 2, SampleRate: 44100, ChannelCount: 2}) require.NoError(t, err) m, err := NewMuxer(3, 1*time.Second, videoTrack, audioTrack) @@ -106,10 +108,12 @@ func TestMuxer(t *testing.T) { } func TestMuxerCloseBeforeFirstSegment(t *testing.T) { - videoTrack, err := gortsplib.NewTrackH264(96, &gortsplib.TrackConfigH264{SPS: []byte{0x07, 0x01, 0x02, 0x03}, PPS: []byte{0x08}}) + videoTrack, err := gortsplib.NewTrackH264(96, + &gortsplib.TrackConfigH264{SPS: []byte{0x07, 0x01, 0x02, 0x03}, PPS: []byte{0x08}}) require.NoError(t, err) - audioTrack, err := gortsplib.NewTrackAAC(97, &gortsplib.TrackConfigAAC{Type: 2, SampleRate: 44100, ChannelCount: 2}) + audioTrack, err := gortsplib.NewTrackAAC(97, + &gortsplib.TrackConfigAAC{Type: 2, SampleRate: 44100, ChannelCount: 2}) require.NoError(t, err) m, err := NewMuxer(3, 1*time.Second, videoTrack, audioTrack)