diff --git a/.golangci.yml b/.golangci.yml index e10b982a..1911cbfc 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -67,6 +67,9 @@ linters: disable: - fieldalignment - reflectvaluecompare + settings: + shadow: + strict: true formatters: enable: diff --git a/internal/auth/manager.go b/internal/auth/manager.go index 8a9f9aac..f6777e4d 100644 --- a/internal/auth/manager.go +++ b/internal/auth/manager.go @@ -206,7 +206,7 @@ func (m *Manager) authenticateHTTP(req *Request) error { defer res.Body.Close() if res.StatusCode < 200 || res.StatusCode > 299 { - if resBody, err := io.ReadAll(res.Body); err == nil && len(resBody) != 0 { + if resBody, err2 := io.ReadAll(res.Body); err2 == nil && len(resBody) != 0 { return fmt.Errorf("server replied with code %d: %s", res.StatusCode, string(resBody)) } diff --git a/internal/auth/manager_test.go b/internal/auth/manager_test.go index eea65b77..5f72cd17 100644 --- a/internal/auth/manager_test.go +++ b/internal/auth/manager_test.go @@ -242,7 +242,7 @@ func TestAuthHTTP(t *testing.T) { } if outcome == "ok" { - err := m.Authenticate(&Request{ + err = m.Authenticate(&Request{ Action: conf.AuthActionPublish, Path: "teststream", Query: "param=value", @@ -255,7 +255,7 @@ func TestAuthHTTP(t *testing.T) { }) require.NoError(t, err) } else { - err := m.Authenticate(&Request{ + err = m.Authenticate(&Request{ Action: conf.AuthActionPublish, Path: "teststream", Query: "param=value", @@ -548,7 +548,8 @@ func TestAuthJWTRefresh(t *testing.T) { token := jwt.NewWithClaims(jwt.SigningMethodRS256, claims) token.Header[jwkset.HeaderKID] = "test-key-id" - ss, err := token.SignedString(key) + var ss string + ss, err = token.SignedString(key) require.NoError(t, err) err = m.Authenticate(&Request{ diff --git a/internal/conf/env/env.go b/internal/conf/env/env.go index 13151b18..64035742 100644 --- a/internal/conf/env/env.go +++ b/internal/conf/env/env.go @@ -31,7 +31,7 @@ func loadEnvInternal(env map[string]string, prefix string, prv reflect.Value) er rt := prv.Type().Elem() if i, ok := prv.Interface().(Unmarshaler); ok { - if ev, ok := env[prefix]; ok { + if ev, ok2 := env[prefix]; ok2 { if prv.IsNil() { prv.Set(reflect.New(rt)) i = prv.Interface().(Unmarshaler) diff --git a/internal/confwatcher/confwatcher_test.go b/internal/confwatcher/confwatcher_test.go index 11816552..f6c46386 100644 --- a/internal/confwatcher/confwatcher_test.go +++ b/internal/confwatcher/confwatcher_test.go @@ -25,7 +25,8 @@ func TestWrite(t *testing.T) { defer w.Close() func() { - f, err := os.Create(fpath) + var f *os.File + f, err = os.Create(fpath) require.NoError(t, err) defer f.Close() @@ -51,23 +52,23 @@ func TestWriteMultipleTimes(t *testing.T) { defer w.Close() func() { - f, err := os.Create(fpath) - require.NoError(t, err) + f, err2 := os.Create(fpath) + require.NoError(t, err2) defer f.Close() - _, err = f.Write([]byte("{}")) - require.NoError(t, err) + _, err2 = f.Write([]byte("{}")) + require.NoError(t, err2) }() time.Sleep(10 * time.Millisecond) func() { - f, err := os.Create(fpath) - require.NoError(t, err) + f, err2 := os.Create(fpath) + require.NoError(t, err2) defer f.Close() - _, err = f.Write([]byte("{}")) - require.NoError(t, err) + _, err2 = f.Write([]byte("{}")) + require.NoError(t, err2) }() select { @@ -98,7 +99,8 @@ func TestDeleteCreate(t *testing.T) { time.Sleep(10 * time.Millisecond) func() { - f, err := os.Create(fpath) + var f *os.File + f, err = os.Create(fpath) require.NoError(t, err) defer f.Close() @@ -129,12 +131,12 @@ func TestSymlinkDeleteCreate(t *testing.T) { os.Remove(fpath) func() { - f, err := os.Create(fpath) - require.NoError(t, err) + f, err2 := os.Create(fpath) + require.NoError(t, err2) defer f.Close() - _, err = f.Write([]byte("{}")) - require.NoError(t, err) + _, err2 = f.Write([]byte("{}")) + require.NoError(t, err2) }() select { diff --git a/internal/core/api_test.go b/internal/core/api_test.go index 7605d453..685e9918 100644 --- a/internal/core/api_test.go +++ b/internal/core/api_test.go @@ -394,7 +394,7 @@ func TestAPIProtocolListGet(t *testing.T) { case "rtsp conns", "rtsp sessions": source := gortsplib.Client{} - err := source.StartRecording("rtsp://localhost:8554/mypath?key=val", + err = source.StartRecording("rtsp://localhost:8554/mypath?key=val", &description.Session{Medias: []*description.Media{medi}}) require.NoError(t, err) defer source.Close() @@ -404,7 +404,7 @@ func TestAPIProtocolListGet(t *testing.T) { TLSConfig: &tls.Config{InsecureSkipVerify: true}, } - err := source.StartRecording("rtsps://localhost:8322/mypath?key=val", + err = source.StartRecording("rtsps://localhost:8322/mypath?key=val", &description.Session{Medias: []*description.Media{medi}}) require.NoError(t, err) defer source.Close() @@ -427,7 +427,8 @@ func TestAPIProtocolListGet(t *testing.T) { rawURL += "127.0.0.1:" + port + "/mypath?key=val" - u, err := url.Parse(rawURL) + var u *url.URL + u, err = url.Parse(rawURL) require.NoError(t, err) conn := &rtmp.Client{ @@ -453,7 +454,7 @@ func TestAPIProtocolListGet(t *testing.T) { case "hls": source := gortsplib.Client{} - err := source.StartRecording("rtsp://localhost:8554/mypath", + err = source.StartRecording("rtsp://localhost:8554/mypath", &description.Session{Medias: []*description.Media{medi}}) require.NoError(t, err) defer source.Close() @@ -483,7 +484,7 @@ func TestAPIProtocolListGet(t *testing.T) { 0x00, 0x00, 0x03, 0x00, 0xf0, 0x3c, 0x60, 0xc9, 0x20, },*/ - err := source.WritePacketRTP(medi, &rtp.Packet{ + err2 := source.WritePacketRTP(medi, &rtp.Packet{ Header: rtp.Header{ Version: 2, Marker: true, @@ -497,25 +498,26 @@ func TestAPIProtocolListGet(t *testing.T) { 0x05, }, }) - require.NoError(t, err) + require.NoError(t, err2) } }() func() { - res, err := hc.Get("http://localhost:8888/mypath/index.m3u8") - require.NoError(t, err) + res, err2 := hc.Get("http://localhost:8888/mypath/index.m3u8") + require.NoError(t, err2) defer res.Body.Close() require.Equal(t, 200, res.StatusCode) }() case "webrtc": source := gortsplib.Client{} - err := source.StartRecording("rtsp://localhost:8554/mypath", + err = source.StartRecording("rtsp://localhost:8554/mypath", &description.Session{Medias: []*description.Media{medi}}) require.NoError(t, err) defer source.Close() - u, err := url.Parse("http://localhost:8889/mypath/whep?key=val") + var u *url.URL + u, err = url.Parse("http://localhost:8889/mypath/whep?key=val") require.NoError(t, err) go func() { @@ -549,7 +551,8 @@ func TestAPIProtocolListGet(t *testing.T) { conf := srt.DefaultConfig() conf.StreamId = "publish:mypath:::key=val" - conn, err := srt.Dial("srt", "localhost:8890", conf) + var conn srt.Conn + conn, err = srt.Dial("srt", "localhost:8890", conf) require.NoError(t, err) defer conn.Close() @@ -927,10 +930,12 @@ func TestAPIProtocolGetNotFound(t *testing.T) { } func() { - req, err := http.NewRequest(http.MethodGet, "http://localhost:9997/v3/"+pa+"/get/"+uuid.New().String(), nil) + var req *http.Request + req, err = http.NewRequest(http.MethodGet, "http://localhost:9997/v3/"+pa+"/get/"+uuid.New().String(), nil) require.NoError(t, err) - res, err := hc.Do(req) + var res *http.Response + res, err = hc.Do(req) require.NoError(t, err) defer res.Body.Close() @@ -994,7 +999,7 @@ func TestAPIProtocolKick(t *testing.T) { case "rtsp": source := gortsplib.Client{} - err := source.StartRecording("rtsp://localhost:8554/mypath", + err = source.StartRecording("rtsp://localhost:8554/mypath", &description.Session{Medias: []*description.Media{medi}}) require.NoError(t, err) defer source.Close() @@ -1004,13 +1009,14 @@ func TestAPIProtocolKick(t *testing.T) { TLSConfig: &tls.Config{InsecureSkipVerify: true}, } - err := source.StartRecording("rtsps://localhost:8322/mypath", + err = source.StartRecording("rtsps://localhost:8322/mypath", &description.Session{Medias: []*description.Media{medi}}) require.NoError(t, err) defer source.Close() case "rtmp": - u, err := url.Parse("rtmp://localhost:1935/mypath") + var u *url.URL + u, err = url.Parse("rtmp://localhost:1935/mypath") require.NoError(t, err) conn := &rtmp.Client{ @@ -1032,7 +1038,8 @@ func TestAPIProtocolKick(t *testing.T) { require.NoError(t, err) case "webrtc": - u, err := url.Parse("http://localhost:8889/mypath/whip") + var u *url.URL + u, err = url.Parse("http://localhost:8889/mypath/whip") require.NoError(t, err) track := &webrtc.OutgoingTrack{ @@ -1061,7 +1068,8 @@ func TestAPIProtocolKick(t *testing.T) { conf := srt.DefaultConfig() conf.StreamId = "publish:mypath" - conn, err := srt.Dial("srt", "localhost:8890", conf) + var conn srt.Conn + conn, err = srt.Dial("srt", "localhost:8890", conf) require.NoError(t, err) defer conn.Close() @@ -1175,10 +1183,12 @@ func TestAPIProtocolKickNotFound(t *testing.T) { } func() { - req, err := http.NewRequest(http.MethodPost, "http://localhost:9997/v3/"+pa+"/kick/"+uuid.New().String(), nil) + var req *http.Request + req, err = http.NewRequest(http.MethodPost, "http://localhost:9997/v3/"+pa+"/kick/"+uuid.New().String(), nil) require.NoError(t, err) - res, err := hc.Do(req) + var res *http.Response + res, err = hc.Do(req) require.NoError(t, err) defer res.Body.Close() diff --git a/internal/core/metrics_test.go b/internal/core/metrics_test.go index 48017dea..96c82967 100644 --- a/internal/core/metrics_test.go +++ b/internal/core/metrics_test.go @@ -176,9 +176,9 @@ webrtc_sessions_bytes_sent 0 go func() { defer wg.Done() source := gortsplib.Client{} - err := source.StartRecording("rtsp://localhost:8554/rtsp_path", + err2 := source.StartRecording("rtsp://localhost:8554/rtsp_path", &description.Session{Medias: []*description.Media{test.UniqueMediaH264()}}) - require.NoError(t, err) + require.NoError(t, err2) defer source.Close() <-terminate }() @@ -186,9 +186,9 @@ webrtc_sessions_bytes_sent 0 go func() { defer wg.Done() source2 := gortsplib.Client{TLSConfig: &tls.Config{InsecureSkipVerify: true}} - err := source2.StartRecording("rtsps://localhost:8322/rtsps_path", + err2 := source2.StartRecording("rtsps://localhost:8322/rtsps_path", &description.Session{Medias: []*description.Media{test.UniqueMediaH264()}}) - require.NoError(t, err) + require.NoError(t, err2) defer source2.Close() <-terminate }() @@ -196,26 +196,26 @@ webrtc_sessions_bytes_sent 0 go func() { defer wg.Done() - u, err := url.Parse("rtmp://localhost:1935/rtmp_path") - require.NoError(t, err) + u, err2 := url.Parse("rtmp://localhost:1935/rtmp_path") + require.NoError(t, err2) conn := &rtmp.Client{ URL: u, Publish: true, } - err = conn.Initialize(context.Background()) - require.NoError(t, err) + err2 = conn.Initialize(context.Background()) + require.NoError(t, err2) defer conn.Close() w := &rtmp.Writer{ Conn: conn, VideoTrack: test.FormatH264, } - err = w.Initialize() - require.NoError(t, err) + err2 = w.Initialize() + require.NoError(t, err2) - err = w.WriteH264(2*time.Second, 2*time.Second, [][]byte{{5, 2, 3, 4}}) - require.NoError(t, err) + err2 = w.WriteH264(2*time.Second, 2*time.Second, [][]byte{{5, 2, 3, 4}}) + require.NoError(t, err2) <-terminate }() @@ -223,27 +223,27 @@ webrtc_sessions_bytes_sent 0 go func() { defer wg.Done() - u, err := url.Parse("rtmps://localhost:1936/rtmps_path") - require.NoError(t, err) + u, err2 := url.Parse("rtmps://localhost:1936/rtmps_path") + require.NoError(t, err2) conn := &rtmp.Client{ URL: u, TLSConfig: &tls.Config{InsecureSkipVerify: true}, Publish: true, } - err = conn.Initialize(context.Background()) - require.NoError(t, err) + err2 = conn.Initialize(context.Background()) + require.NoError(t, err2) defer conn.Close() w := &rtmp.Writer{ Conn: conn, VideoTrack: test.FormatH264, } - err = w.Initialize() - require.NoError(t, err) + err2 = w.Initialize() + require.NoError(t, err2) - err = w.WriteH264(2*time.Second, 2*time.Second, [][]byte{{5, 2, 3, 4}}) - require.NoError(t, err) + err2 = w.WriteH264(2*time.Second, 2*time.Second, [][]byte{{5, 2, 3, 4}}) + require.NoError(t, err2) <-terminate }() @@ -251,12 +251,12 @@ webrtc_sessions_bytes_sent 0 go func() { defer wg.Done() - su, err := url.Parse("http://localhost:8889/webrtc_path/whip") - require.NoError(t, err) + su, err2 := url.Parse("http://localhost:8889/webrtc_path/whip") + require.NoError(t, err2) - tr := &http.Transport{} - defer tr.CloseIdleConnections() - hc2 := &http.Client{Transport: tr} + tr2 := &http.Transport{} + defer tr2.CloseIdleConnections() + hc2 := &http.Client{Transport: tr2} track := &webrtc.OutgoingTrack{ Caps: pwebrtc.RTPCodecCapability{ @@ -274,11 +274,11 @@ webrtc_sessions_bytes_sent 0 OutgoingTracks: []*webrtc.OutgoingTrack{track}, } - err = s.Initialize(context.Background()) - require.NoError(t, err) + err2 = s.Initialize(context.Background()) + require.NoError(t, err2) defer checkClose(t, s.Close) - err = track.WriteRTP(&rtp.Packet{ + err2 = track.WriteRTP(&rtp.Packet{ Header: rtp.Header{ Version: 2, Marker: true, @@ -289,7 +289,7 @@ webrtc_sessions_bytes_sent 0 }, Payload: []byte{1}, }) - require.NoError(t, err) + require.NoError(t, err2) <-terminate }() @@ -297,14 +297,14 @@ webrtc_sessions_bytes_sent 0 defer wg.Done() srtConf := srt.DefaultConfig() - address, err := srtConf.UnmarshalURL("srt://localhost:8890?streamid=publish:srt_path") - require.NoError(t, err) + address, err2 := srtConf.UnmarshalURL("srt://localhost:8890?streamid=publish:srt_path") + require.NoError(t, err2) - err = srtConf.Validate() - require.NoError(t, err) + err2 = srtConf.Validate() + require.NoError(t, err2) - publisher, err := srt.Dial("srt", address, srtConf) - require.NoError(t, err) + publisher, err2 := srt.Dial("srt", address, srtConf) + require.NoError(t, err2) defer publisher.Close() track := &mpegts.Track{ @@ -313,18 +313,18 @@ webrtc_sessions_bytes_sent 0 bw := bufio.NewWriter(publisher) w := &mpegts.Writer{W: bw, Tracks: []*mpegts.Track{track}} - err = w.Initialize() - require.NoError(t, err) + err2 = w.Initialize() + require.NoError(t, err2) - err = w.WriteH264(track, 0, 0, [][]byte{ + err2 = w.WriteH264(track, 0, 0, [][]byte{ test.FormatH264.SPS, test.FormatH264.PPS, {0x05, 1}, // IDR }) - require.NoError(t, err) + require.NoError(t, err2) - err = bw.Flush() - require.NoError(t, err) + err2 = bw.Flush() + require.NoError(t, err2) <-terminate }() diff --git a/internal/core/path.go b/internal/core/path.go index c1c33bd0..23b93356 100644 --- a/internal/core/path.go +++ b/internal/core/path.go @@ -224,7 +224,7 @@ func (pa *path) run() { if !pa.conf.SourceOnDemand || pa.onDemandStaticSourceState != pathOnDemandStateInitial { source.Close("path is closing") } - } else if source, ok := pa.source.(defs.Publisher); ok { + } else if source, ok2 := pa.source.(defs.Publisher); ok2 { source.Close() } } diff --git a/internal/core/path_manager_test.go b/internal/core/path_manager_test.go index e78331b0..c4c66b50 100644 --- a/internal/core/path_manager_test.go +++ b/internal/core/path_manager_test.go @@ -32,7 +32,8 @@ func TestPathAutoDeletion(t *testing.T) { br := bufio.NewReader(conn) if ca == "describe" { - u, err := base.ParseURL("rtsp://localhost:8554/mypath") + var u *base.URL + u, err = base.ParseURL("rtsp://localhost:8554/mypath") require.NoError(t, err) byts, _ := base.Request{ @@ -50,7 +51,8 @@ func TestPathAutoDeletion(t *testing.T) { require.NoError(t, err) require.Equal(t, base.StatusNotFound, res.StatusCode) } else { - u, err := base.ParseURL("rtsp://localhost:8554/mypath/trackID=0") + var u *base.URL + u, err = base.ParseURL("rtsp://localhost:8554/mypath/trackID=0") require.NoError(t, err) byts, _ := base.Request{ diff --git a/internal/core/path_test.go b/internal/core/path_test.go index 2becc779..f48ede67 100644 --- a/internal/core/path_test.go +++ b/internal/core/path_test.go @@ -79,7 +79,8 @@ func TestPathRunOnDemand(t *testing.T) { br := bufio.NewReader(conn) if ca == "describe" || ca == "describe and setup" { - u, err := base.ParseURL("rtsp://localhost:8554/ondemand?param=value") + var u *base.URL + u, err = base.ParseURL("rtsp://localhost:8554/ondemand?param=value") require.NoError(t, err) byts, _ := base.Request{ @@ -107,7 +108,8 @@ func TestPathRunOnDemand(t *testing.T) { } if ca == "setup" || ca == "describe and setup" { - u, err := base.ParseURL(control) + var u *base.URL + u, err = base.ParseURL(control) require.NoError(t, err) byts, _ := base.Request{ @@ -190,7 +192,7 @@ func TestPathRunOnConnect(t *testing.T) { c := gortsplib.Client{} - err := c.StartRecording( + err = c.StartRecording( "rtsp://localhost:8554/test", &description.Session{Medias: []*description.Media{test.UniqueMediaH264()}}) require.NoError(t, err) @@ -201,7 +203,7 @@ func TestPathRunOnConnect(t *testing.T) { c := gortsplib.Client{TLSConfig: &tls.Config{InsecureSkipVerify: true}} - err := c.StartRecording( + err = c.StartRecording( "rtsps://localhost:8322/test", &description.Session{Medias: []*description.Media{test.UniqueMediaH264()}}) require.NoError(t, err) @@ -210,7 +212,8 @@ func TestPathRunOnConnect(t *testing.T) { case "rtmp": connType = "rtmpConn" - u, err := url.Parse("rtmp://127.0.0.1:1935/test") + var u *url.URL + u, err = url.Parse("rtmp://127.0.0.1:1935/test") require.NoError(t, err) conn := &rtmp.Client{ @@ -224,7 +227,8 @@ func TestPathRunOnConnect(t *testing.T) { case "rtmps": connType = "rtmpsConn" - u, err := url.Parse("rtmps://127.0.0.1:1936/test") + var u *url.URL + u, err = url.Parse("rtmps://127.0.0.1:1936/test") require.NoError(t, err) conn := &rtmp.Client{ @@ -240,13 +244,15 @@ func TestPathRunOnConnect(t *testing.T) { connType = "srtConn" conf := srt.DefaultConfig() - address, err := conf.UnmarshalURL("srt://localhost:8890?streamid=publish:test") + var address string + address, err = conf.UnmarshalURL("srt://localhost:8890?streamid=publish:test") require.NoError(t, err) err = conf.Validate() require.NoError(t, err) - c, err := srt.Dial("srt", address, conf) + var c srt.Conn + c, err = srt.Dial("srt", address, conf) require.NoError(t, err) defer c.Close() } @@ -254,7 +260,8 @@ func TestPathRunOnConnect(t *testing.T) { time.Sleep(500 * time.Millisecond) }() - byts, err := os.ReadFile(onConnect) + var byts []byte + byts, err = os.ReadFile(onConnect) require.NoError(t, err) fields := strings.Split(string(byts[:len(byts)-1]), " ") require.Equal(t, connType, fields[0]) @@ -359,7 +366,7 @@ func TestPathRunOnRead(t *testing.T) { source := gortsplib.Client{} - err := source.StartRecording( + err = source.StartRecording( "rtsp://localhost:8554/test", &description.Session{Medias: []*description.Media{media0}}) require.NoError(t, err) @@ -398,7 +405,8 @@ func TestPathRunOnRead(t *testing.T) { switch ca { case "rtsp": - u, err := base.ParseURL("rtsp://127.0.0.1:8554/test?query=value") + var u *base.URL + u, err = base.ParseURL("rtsp://127.0.0.1:8554/test?query=value") require.NoError(t, err) reader := gortsplib.Client{ @@ -410,7 +418,8 @@ func TestPathRunOnRead(t *testing.T) { require.NoError(t, err) defer reader.Close() - desc, _, err := reader.Describe(u) + var desc *description.Session + desc, _, err = reader.Describe(u) require.NoError(t, err) err = reader.SetupAll(desc.BaseURL, desc.Medias) @@ -420,7 +429,8 @@ func TestPathRunOnRead(t *testing.T) { require.NoError(t, err) case "rtsps": - u, err := base.ParseURL("rtsps://127.0.0.1:8322/test?query=value") + var u *base.URL + u, err = base.ParseURL("rtsps://127.0.0.1:8322/test?query=value") require.NoError(t, err) reader := gortsplib.Client{ @@ -433,7 +443,8 @@ func TestPathRunOnRead(t *testing.T) { require.NoError(t, err) defer reader.Close() - desc, _, err := reader.Describe(u) + var desc *description.Session + desc, _, err = reader.Describe(u) require.NoError(t, err) err = reader.SetupAll(desc.BaseURL, desc.Medias) @@ -443,7 +454,8 @@ func TestPathRunOnRead(t *testing.T) { require.NoError(t, err) case "rtmp": - u, err := url.Parse("rtmp://127.0.0.1:1935/test?query=value") + var u *url.URL + u, err = url.Parse("rtmp://127.0.0.1:1935/test?query=value") require.NoError(t, err) conn := &rtmp.Client{ @@ -461,7 +473,8 @@ func TestPathRunOnRead(t *testing.T) { require.NoError(t, err) case "rtmps": - u, err := url.Parse("rtmps://127.0.0.1:1936/test?query=value") + var u *url.URL + u, err = url.Parse("rtmps://127.0.0.1:1936/test?query=value") require.NoError(t, err) conn := &rtmp.Client{ @@ -498,13 +511,15 @@ func TestPathRunOnRead(t *testing.T) { case "srt": conf := srt.DefaultConfig() - address, err := conf.UnmarshalURL("srt://localhost:8890?streamid=read:test:query=value") + var address string + address, err = conf.UnmarshalURL("srt://localhost:8890?streamid=read:test:query=value") require.NoError(t, err) err = conf.Validate() require.NoError(t, err) - reader, err := srt.Dial("srt", address, conf) + var reader srt.Conn + reader, err = srt.Dial("srt", address, conf) require.NoError(t, err) defer reader.Close() @@ -513,7 +528,8 @@ func TestPathRunOnRead(t *testing.T) { defer tr.CloseIdleConnections() hc := &http.Client{Transport: tr} - u, err := url.Parse("http://localhost:8889/test/whep?query=value") + var u *url.URL + u, err = url.Parse("http://localhost:8889/test/whep?query=value") require.NoError(t, err) c := &whip.Client{ @@ -547,7 +563,8 @@ func TestPathRunOnRead(t *testing.T) { readerType = "webRTCSession" } - byts, err := os.ReadFile(onRead) + var byts []byte + byts, err = os.ReadFile(onRead) require.NoError(t, err) fields := strings.Split(string(byts[:len(byts)-1]), " ") require.Equal(t, "test", fields[0]) @@ -656,7 +673,8 @@ func TestPathMaxReaders(t *testing.T) { defer source.Close() for i := 0; i < 2; i++ { - u, err := base.ParseURL("rtsp://127.0.0.1:8554/mystream") + var u *base.URL + u, err = base.ParseURL("rtsp://127.0.0.1:8554/mystream") require.NoError(t, err) reader := gortsplib.Client{ @@ -668,7 +686,8 @@ func TestPathMaxReaders(t *testing.T) { require.NoError(t, err) defer reader.Close() - desc, _, err := reader.Describe(u) + var desc *description.Session + desc, _, err = reader.Describe(u) require.NoError(t, err) err = reader.SetupAll(desc.BaseURL, desc.Medias) diff --git a/internal/core/versiongetter/main.go b/internal/core/versiongetter/main.go index cdf4fe9c..0bfe5398 100644 --- a/internal/core/versiongetter/main.go +++ b/internal/core/versiongetter/main.go @@ -13,6 +13,7 @@ import ( "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing/cache" + "github.com/go-git/go-git/v5/plumbing/object" "github.com/go-git/go-git/v5/storage/filesystem" ) @@ -51,7 +52,8 @@ func gitDescribeTags(repo *git.Repository) (string, error) { i := 0 for { - commit, err := cIter.Next() + var commit *object.Commit + commit, err = cIter.Next() if err != nil { return "", fmt.Errorf("failed to get next commit: %w", err) } diff --git a/internal/externalcmd/cmd_unix.go b/internal/externalcmd/cmd_unix.go index c8c39ecd..ff08e801 100644 --- a/internal/externalcmd/cmd_unix.go +++ b/internal/externalcmd/cmd_unix.go @@ -35,12 +35,12 @@ func (e *Cmd) runOSSpecific(env []string) error { cmdDone := make(chan int) go func() { cmdDone <- func() int { - err := cmd.Wait() - if err == nil { + err2 := cmd.Wait() + if err2 == nil { return 0 } var ee *exec.ExitError - if errors.As(err, &ee) { + if errors.As(err2, &ee) { ee.ExitCode() } return 0 diff --git a/internal/formatprocessor/h264_test.go b/internal/formatprocessor/h264_test.go index 9b028621..09436ef0 100644 --- a/internal/formatprocessor/h264_test.go +++ b/internal/formatprocessor/h264_test.go @@ -226,7 +226,8 @@ func TestH264ProcessRTPPacketOversized(t *testing.T) { Payload: []byte{0x1c, 0b01000000, 0x01, 0x02, 0x03, 0x04}, }, } { - data, err := p.ProcessRTPPacket(pkt, time.Time{}, 0, false) + var data unit.Unit + data, err = p.ProcessRTPPacket(pkt, time.Time{}, 0, false) require.NoError(t, err) out = append(out, data.GetRTPPackets()...) diff --git a/internal/formatprocessor/h265_test.go b/internal/formatprocessor/h265_test.go index 3235c6c3..65eb52cc 100644 --- a/internal/formatprocessor/h265_test.go +++ b/internal/formatprocessor/h265_test.go @@ -213,7 +213,8 @@ func TestH265ProcessRTPPacketOversized(t *testing.T) { Payload: bytes.Repeat([]byte{0x01, 0x02, 0x03, 0x04}, 2000/4), }, } { - data, err := p.ProcessRTPPacket(pkt, time.Time{}, 0, false) + var data unit.Unit + data, err = p.ProcessRTPPacket(pkt, time.Time{}, 0, false) require.NoError(t, err) out = append(out, data.GetRTPPackets()...) diff --git a/internal/metrics/metrics.go b/internal/metrics/metrics.go index 31e27867..a20e975e 100644 --- a/internal/metrics/metrics.go +++ b/internal/metrics/metrics.go @@ -168,7 +168,8 @@ func (m *Metrics) onMetrics(ctx *gin.Context) { } if !interfaceIsEmpty(m.hlsServer) { - data, err := m.hlsServer.APIMuxersList() + var data *defs.APIHLSMuxerList + data, err = m.hlsServer.APIMuxersList() if err == nil && len(data.Items) != 0 { for _, i := range data.Items { tags := "{name=\"" + i.Path + "\"}" @@ -183,7 +184,8 @@ func (m *Metrics) onMetrics(ctx *gin.Context) { if !interfaceIsEmpty(m.rtspServer) { //nolint:dupl func() { - data, err := m.rtspServer.APIConnsList() + var data *defs.APIRTSPConnsList + data, err = m.rtspServer.APIConnsList() if err == nil && len(data.Items) != 0 { for _, i := range data.Items { tags := "{id=\"" + i.ID.String() + "\"}" @@ -199,7 +201,8 @@ func (m *Metrics) onMetrics(ctx *gin.Context) { }() func() { - data, err := m.rtspServer.APISessionsList() + var data *defs.APIRTSPSessionList + data, err = m.rtspServer.APISessionsList() if err == nil && len(data.Items) != 0 { for _, i := range data.Items { tags := "{id=\"" + i.ID.String() + "\",state=\"" + string(i.State) + "\"}" @@ -233,7 +236,8 @@ func (m *Metrics) onMetrics(ctx *gin.Context) { if !interfaceIsEmpty(m.rtspsServer) { //nolint:dupl func() { - data, err := m.rtspsServer.APIConnsList() + var data *defs.APIRTSPConnsList + data, err = m.rtspsServer.APIConnsList() if err == nil && len(data.Items) != 0 { for _, i := range data.Items { tags := "{id=\"" + i.ID.String() + "\"}" @@ -249,7 +253,8 @@ func (m *Metrics) onMetrics(ctx *gin.Context) { }() func() { - data, err := m.rtspsServer.APISessionsList() + var data *defs.APIRTSPSessionList + data, err = m.rtspsServer.APISessionsList() if err == nil && len(data.Items) != 0 { for _, i := range data.Items { tags := "{id=\"" + i.ID.String() + "\",state=\"" + string(i.State) + "\"}" @@ -282,7 +287,8 @@ func (m *Metrics) onMetrics(ctx *gin.Context) { } if !interfaceIsEmpty(m.rtmpServer) { - data, err := m.rtmpServer.APIConnsList() + var data *defs.APIRTMPConnList + data, err = m.rtmpServer.APIConnsList() if err == nil && len(data.Items) != 0 { for _, i := range data.Items { tags := "{id=\"" + i.ID.String() + "\",state=\"" + string(i.State) + "\"}" @@ -298,7 +304,8 @@ func (m *Metrics) onMetrics(ctx *gin.Context) { } if !interfaceIsEmpty(m.rtmpsServer) { - data, err := m.rtmpsServer.APIConnsList() + var data *defs.APIRTMPConnList + data, err = m.rtmpsServer.APIConnsList() if err == nil && len(data.Items) != 0 { for _, i := range data.Items { tags := "{id=\"" + i.ID.String() + "\",state=\"" + string(i.State) + "\"}" @@ -314,7 +321,8 @@ func (m *Metrics) onMetrics(ctx *gin.Context) { } if !interfaceIsEmpty(m.srtServer) { - data, err := m.srtServer.APIConnsList() + var data *defs.APISRTConnList + data, err = m.srtServer.APIConnsList() if err == nil && len(data.Items) != 0 { for _, i := range data.Items { tags := "{id=\"" + i.ID.String() + "\",state=\"" + string(i.State) + "\"}" @@ -428,7 +436,8 @@ func (m *Metrics) onMetrics(ctx *gin.Context) { } if !interfaceIsEmpty(m.webRTCServer) { - data, err := m.webRTCServer.APISessionsList() + var data *defs.APIWebRTCSessionList + data, err = m.webRTCServer.APISessionsList() if err == nil && len(data.Items) != 0 { for _, i := range data.Items { tags := "{id=\"" + i.ID.String() + "\",state=\"" + string(i.State) + "\"}" diff --git a/internal/playback/muxer_fmp4.go b/internal/playback/muxer_fmp4.go index 87bceabc..a7ee99e0 100644 --- a/internal/playback/muxer_fmp4.go +++ b/internal/playback/muxer_fmp4.go @@ -97,7 +97,7 @@ func (w *muxerFMP4) writeSample( partDurationMP4 := durationGoToMp4(partDuration, w.curTrack.timeScale) if (w.curTrack.lastDTS - w.curTrack.firstDTS) >= partDurationMP4 { - err := w.innerFlush(false) + err = w.innerFlush(false) if err != nil { return err } diff --git a/internal/playback/on_get.go b/internal/playback/on_get.go index 386f6d10..1e70e61d 100644 --- a/internal/playback/on_get.go +++ b/internal/playback/on_get.go @@ -90,9 +90,8 @@ func seekAndMux( break } - segmentStartOffset := seg.Start.Sub(start) // this is positive + segmentStartOffset = seg.Start.Sub(start) // this is positive - var segmentDuration time.Duration segmentDuration, err = segmentFMP4MuxParts(f, segmentStartOffset, duration, firstInit.Tracks, m) if err != nil { return err diff --git a/internal/playback/on_get_test.go b/internal/playback/on_get_test.go index 14a43288..d4384248 100644 --- a/internal/playback/on_get_test.go +++ b/internal/playback/on_get_test.go @@ -375,7 +375,7 @@ func TestOnGet(t *testing.T) { for _, track := range p.Tracks { var samples [][]byte for _, sample := range track.Samples { - buf, err := sample.GetPayload() + buf, err = sample.GetPayload() require.NoError(t, err) samples = append(samples, buf) sample.GetPayload = nil diff --git a/internal/playback/segment_fmp4.go b/internal/playback/segment_fmp4.go index 104ee892..c9252dea 100644 --- a/internal/playback/segment_fmp4.go +++ b/internal/playback/segment_fmp4.go @@ -275,7 +275,7 @@ func segmentFMP4ReadDurationFromParts( outer: for { - _, err := io.ReadFull(r, buf) + _, err = io.ReadFull(r, buf) if err != nil { return 0, err } diff --git a/internal/protocols/mpegts/from_stream.go b/internal/protocols/mpegts/from_stream.go index c227bd92..3a81f03e 100644 --- a/internal/protocols/mpegts/from_stream.go +++ b/internal/protocols/mpegts/from_stream.go @@ -64,6 +64,7 @@ func FromStream( track, func(u unit.Unit) error { tunit := u.(*unit.H265) + if tunit.AU == nil { return nil } @@ -106,6 +107,7 @@ func FromStream( track, func(u unit.Unit) error { tunit := u.(*unit.H264) + if tunit.AU == nil { return nil } @@ -149,6 +151,7 @@ func FromStream( track, func(u unit.Unit) error { tunit := u.(*unit.MPEG4Video) + if tunit.Frame == nil { return nil } @@ -183,6 +186,7 @@ func FromStream( track, func(u unit.Unit) error { tunit := u.(*unit.MPEG1Video) + if tunit.Frame == nil { return nil } @@ -216,6 +220,7 @@ func FromStream( track, func(u unit.Unit) error { tunit := u.(*unit.Opus) + if tunit.Packets == nil { return nil } @@ -243,6 +248,7 @@ func FromStream( track, func(u unit.Unit) error { tunit := u.(*unit.KLV) + if tunit.Unit == nil { return nil } @@ -266,6 +272,7 @@ func FromStream( track, func(u unit.Unit) error { tunit := u.(*unit.MPEG4Audio) + if tunit.AUs == nil { return nil } @@ -291,6 +298,7 @@ func FromStream( track, func(u unit.Unit) error { tunit := u.(*unit.MPEG4AudioLATM) + if tunit.Element == nil { return nil } @@ -330,6 +338,7 @@ func FromStream( track, func(u unit.Unit) error { tunit := u.(*unit.MPEG4AudioLATM) + if tunit.Element == nil { return nil } @@ -355,6 +364,7 @@ func FromStream( track, func(u unit.Unit) error { tunit := u.(*unit.MPEG1Audio) + if tunit.Frames == nil { return nil } @@ -379,6 +389,7 @@ func FromStream( track, func(u unit.Unit) error { tunit := u.(*unit.AC3) + if tunit.Frames == nil { return nil } diff --git a/internal/protocols/rtmp/amf0/data.go b/internal/protocols/rtmp/amf0/data.go index ed266b0d..f7e62f48 100644 --- a/internal/protocols/rtmp/amf0/data.go +++ b/internal/protocols/rtmp/amf0/data.go @@ -366,7 +366,7 @@ func marshalItem(item interface{}, buf []byte) int { n := 5 for _, entry := range item { - le := len(entry.Key) + le = len(entry.Key) buf[n] = byte(le >> 8) buf[n+1] = byte(le) copy(buf[n+2:], entry.Key) diff --git a/internal/protocols/rtmp/from_stream.go b/internal/protocols/rtmp/from_stream.go index f821db78..7aa2dd1e 100644 --- a/internal/protocols/rtmp/from_stream.go +++ b/internal/protocols/rtmp/from_stream.go @@ -147,6 +147,7 @@ func setupAudio( audioFormatMPEG4AudioLATM, func(u unit.Unit) error { tunit := u.(*unit.MPEG4AudioLATM) + if tunit.Element == nil { return nil } diff --git a/internal/protocols/rtmp/message/reader.go b/internal/protocols/rtmp/message/reader.go index eb09089e..30104c0c 100644 --- a/internal/protocols/rtmp/message/reader.go +++ b/internal/protocols/rtmp/message/reader.go @@ -165,7 +165,7 @@ func (r *Reader) Read() (Message, error) { switch tmsg := msg.(type) { case *SetChunkSize: - err := r.r.SetChunkSize(tmsg.Value) + err = r.r.SetChunkSize(tmsg.Value) if err != nil { return nil, err } diff --git a/internal/protocols/rtmp/message/readwriter.go b/internal/protocols/rtmp/message/readwriter.go index fe568807..4f71fb5e 100644 --- a/internal/protocols/rtmp/message/readwriter.go +++ b/internal/protocols/rtmp/message/readwriter.go @@ -44,7 +44,7 @@ func (rw *ReadWriter) Read() (Message, error) { rw.w.SetAcknowledgeValue(tmsg.Value) case *UserControlPingRequest: - err := rw.w.Write(&UserControlPingResponse{ + err = rw.w.Write(&UserControlPingResponse{ ServerTime: tmsg.ServerTime, }) if err != nil { diff --git a/internal/protocols/rtmp/rawmessage/reader.go b/internal/protocols/rtmp/rawmessage/reader.go index 3d165270..d3ad15ee 100644 --- a/internal/protocols/rtmp/rawmessage/reader.go +++ b/internal/protocols/rtmp/rawmessage/reader.go @@ -51,7 +51,7 @@ func (rc *readerChunkStream) readChunk(c chunk.Chunk, bodySize uint32, hasExtend diff := count - rc.mr.lastAckCount if diff > (rc.mr.ackWindowSize) { - err := rc.mr.onAckNeeded(count) + err = rc.mr.onAckNeeded(count) if err != nil { return err } diff --git a/internal/protocols/rtmp/reader.go b/internal/protocols/rtmp/reader.go index 5befb9bd..d702cf18 100644 --- a/internal/protocols/rtmp/reader.go +++ b/internal/protocols/rtmp/reader.go @@ -453,13 +453,13 @@ func (r *Reader) readTracks() (map[uint8]format.Format, map[uint8]format.Format, } case *message.AudioExSequenceStart: - err := handleAudioSequenceStart(0, msg) + err = handleAudioSequenceStart(0, msg) if err != nil { return nil, nil, err } case *message.AudioExCodedFrames: - err := handleAudioCodedFrames(0, msg) + err = handleAudioCodedFrames(0, msg) if err != nil { return nil, nil, err } @@ -471,13 +471,13 @@ func (r *Reader) readTracks() (map[uint8]format.Format, map[uint8]format.Format, switch wmsg := msg.Wrapped.(type) { case *message.AudioExSequenceStart: - err := handleAudioSequenceStart(msg.TrackID, wmsg) + err = handleAudioSequenceStart(msg.TrackID, wmsg) if err != nil { return nil, nil, err } case *message.AudioExCodedFrames: - err := handleAudioCodedFrames(msg.TrackID, wmsg) + err = handleAudioCodedFrames(msg.TrackID, wmsg) if err != nil { return nil, nil, err } diff --git a/internal/protocols/rtmp/server_conn.go b/internal/protocols/rtmp/server_conn.go index 3ca9e456..72cb7c22 100644 --- a/internal/protocols/rtmp/server_conn.go +++ b/internal/protocols/rtmp/server_conn.go @@ -325,7 +325,8 @@ func (c *ServerConn) Accept() error { } for { - cmd, err := readCommand(c.mrw) + var cmd *message.CommandAMF0 + cmd, err = readCommand(c.mrw) if err != nil { return err } diff --git a/internal/protocols/rtmp/server_conn_test.go b/internal/protocols/rtmp/server_conn_test.go index 489f1b9b..4628cb73 100644 --- a/internal/protocols/rtmp/server_conn_test.go +++ b/internal/protocols/rtmp/server_conn_test.go @@ -392,7 +392,8 @@ func TestServerConn(t *testing.T) { }) require.NoError(t, err) - msg, err := mrw.Read() + var msg message.Message + msg, err = mrw.Read() require.NoError(t, err) require.Equal(t, &message.SetWindowAckSize{ Value: 2500000, diff --git a/internal/protocols/rtmp/writer.go b/internal/protocols/rtmp/writer.go index c29a2faa..efecb7b6 100644 --- a/internal/protocols/rtmp/writer.go +++ b/internal/protocols/rtmp/writer.go @@ -137,12 +137,13 @@ func (w *Writer) writeTracks() error { if track, ok := w.AudioTrack.(*format.MPEG4Audio); ok { audioConf = track.Config - } else if track, ok := w.AudioTrack.(*format.MPEG4AudioLATM); ok { + } else if track, ok2 := w.AudioTrack.(*format.MPEG4AudioLATM); ok2 { audioConf = track.StreamMuxConfig.Programs[0].Layers[0].AudioSpecificConfig } if audioConf != nil { - enc, err := audioConf.Marshal() + var enc []byte + enc, err = audioConf.Marshal() if err != nil { return err } diff --git a/internal/protocols/webrtc/from_stream.go b/internal/protocols/webrtc/from_stream.go index 3f344ac9..54f50197 100644 --- a/internal/protocols/webrtc/from_stream.go +++ b/internal/protocols/webrtc/from_stream.go @@ -88,8 +88,8 @@ func setupVideoTrack( return nil } - packets, err := encoder.Encode(tunit.TU) - if err != nil { + packets, err2 := encoder.Encode(tunit.TU) + if err2 != nil { return nil //nolint:nilerr } @@ -139,8 +139,8 @@ func setupVideoTrack( return nil } - packets, err := encoder.Encode(tunit.Frame) - if err != nil { + packets, err2 := encoder.Encode(tunit.Frame) + if err2 != nil { return nil //nolint:nilerr } @@ -188,8 +188,8 @@ func setupVideoTrack( return nil } - packets, err := encoder.Encode(tunit.Frame) - if err != nil { + packets, err2 := encoder.Encode(tunit.Frame) + if err2 != nil { return nil //nolint:nilerr } @@ -248,8 +248,8 @@ func setupVideoTrack( } lastPTS = tunit.PTS - packets, err := encoder.Encode(tunit.AU) - if err != nil { + packets, err2 := encoder.Encode(tunit.AU) + if err2 != nil { return nil //nolint:nilerr } @@ -308,8 +308,8 @@ func setupVideoTrack( } lastPTS = tunit.PTS - packets, err := encoder.Encode(tunit.AU) - if err != nil { + packets, err2 := encoder.Encode(tunit.AU) + if err2 != nil { return nil //nolint:nilerr } @@ -535,8 +535,8 @@ func setupAudioTrack( lpcm = al } - packets, err := encoder.Encode(lpcm) - if err != nil { + packets, err2 := encoder.Encode(lpcm) + if err2 != nil { return nil //nolint:nilerr } @@ -613,8 +613,8 @@ func setupAudioTrack( return nil } - packets, err := encoder.Encode(tunit.Samples) - if err != nil { + packets, err2 := encoder.Encode(tunit.Samples) + if err2 != nil { return nil //nolint:nilerr } diff --git a/internal/protocols/webrtc/incoming_track.go b/internal/protocols/webrtc/incoming_track.go index 7c598f7e..71b3ca47 100644 --- a/internal/protocols/webrtc/incoming_track.go +++ b/internal/protocols/webrtc/incoming_track.go @@ -299,14 +299,14 @@ func (t *IncomingTrack) start() { go func() { buf := make([]byte, 1500) for { - n, _, err := t.receiver.Read(buf) - if err != nil { + n, _, err2 := t.receiver.Read(buf) + if err2 != nil { return } - pkts, err := rtcp.Unmarshal(buf[:n]) - if err != nil { - panic(err) + pkts, err2 := rtcp.Unmarshal(buf[:n]) + if err2 != nil { + panic(err2) } for _, pkt := range pkts { @@ -324,12 +324,12 @@ func (t *IncomingTrack) start() { defer keyframeTicker.Stop() for range keyframeTicker.C { - err := t.writeRTCP([]rtcp.Packet{ + err2 := t.writeRTCP([]rtcp.Packet{ &rtcp.PictureLossIndication{ MediaSSRC: uint32(t.track.SSRC()), }, }) - if err != nil { + if err2 != nil { return } } @@ -342,8 +342,8 @@ func (t *IncomingTrack) start() { reorderer.Initialize() for { - pkt, _, err := t.track.ReadRTP() - if err != nil { + pkt, _, err2 := t.track.ReadRTP() + if err2 != nil { return } @@ -353,9 +353,9 @@ func (t *IncomingTrack) start() { // do not return } - err = t.rtcpReceiver.ProcessPacket(pkt, time.Now(), true) - if err != nil { - t.log.Log(logger.Warn, err.Error()) + err2 = t.rtcpReceiver.ProcessPacket(pkt, time.Now(), true) + if err2 != nil { + t.log.Log(logger.Warn, err2.Error()) continue } diff --git a/internal/protocols/webrtc/outgoing_track.go b/internal/protocols/webrtc/outgoing_track.go index e00a4bc2..354df894 100644 --- a/internal/protocols/webrtc/outgoing_track.go +++ b/internal/protocols/webrtc/outgoing_track.go @@ -73,14 +73,14 @@ func (t *OutgoingTrack) setup(p *PeerConnection) error { go func() { buf := make([]byte, 1500) for { - n, _, err := sender.Read(buf) - if err != nil { + n, _, err2 := sender.Read(buf) + if err2 != nil { return } - _, err = rtcp.Unmarshal(buf[:n]) - if err != nil { - panic(err) + _, err2 = rtcp.Unmarshal(buf[:n]) + if err2 != nil { + panic(err2) } } }() diff --git a/internal/protocols/whip/ice_fragment.go b/internal/protocols/whip/ice_fragment.go index d6dc089b..358661eb 100644 --- a/internal/protocols/whip/ice_fragment.go +++ b/internal/protocols/whip/ice_fragment.go @@ -26,7 +26,8 @@ func ICEFragmentUnmarshal(buf []byte) ([]*webrtc.ICECandidateInit, error) { return nil, fmt.Errorf("mid attribute is missing") } - tmp, err := strconv.ParseUint(mid, 10, 16) + var tmp uint64 + tmp, err = strconv.ParseUint(mid, 10, 16) if err != nil { return nil, fmt.Errorf("invalid mid attribute") } diff --git a/internal/recorder/format_fmp4.go b/internal/recorder/format_fmp4.go index 977b4003..0e432794 100644 --- a/internal/recorder/format_fmp4.go +++ b/internal/recorder/format_fmp4.go @@ -149,6 +149,7 @@ func (f *formatFMP4) initialize() bool { forma, func(u unit.Unit) error { tunit := u.(*unit.AV1) + if tunit.TU == nil { return nil } @@ -215,6 +216,7 @@ func (f *formatFMP4) initialize() bool { forma, func(u unit.Unit) error { tunit := u.(*unit.VP9) + if tunit.Frame == nil { return nil } @@ -305,6 +307,7 @@ func (f *formatFMP4) initialize() bool { forma, func(u unit.Unit) error { tunit := u.(*unit.H265) + if tunit.AU == nil { return nil } @@ -393,6 +396,7 @@ func (f *formatFMP4) initialize() bool { forma, func(u unit.Unit) error { tunit := u.(*unit.H264) + if tunit.AU == nil { return nil } @@ -473,6 +477,7 @@ func (f *formatFMP4) initialize() bool { forma, func(u unit.Unit) error { tunit := u.(*unit.MPEG4Video) + if tunit.Frame == nil { return nil } @@ -482,10 +487,10 @@ func (f *formatFMP4) initialize() bool { if bytes.HasPrefix(tunit.Frame, []byte{0, 0, 1, byte(mpeg4video.VisualObjectSequenceStartCode)}) { end := bytes.Index(tunit.Frame[4:], []byte{0, 0, 1, byte(mpeg4video.GroupOfVOPStartCode)}) if end >= 0 { - config := tunit.Frame[:end+4] + config2 := tunit.Frame[:end+4] - if !bytes.Equal(codec.Config, config) { - codec.Config = config + if !bytes.Equal(codec.Config, config2) { + codec.Config = config2 f.updateCodecParams() } } @@ -526,6 +531,7 @@ func (f *formatFMP4) initialize() bool { forma, func(u unit.Unit) error { tunit := u.(*unit.MPEG1Video) + if tunit.Frame == nil { return nil } @@ -579,6 +585,7 @@ func (f *formatFMP4) initialize() bool { forma, func(u unit.Unit) error { tunit := u.(*unit.MJPEG) + if tunit.Frame == nil { return nil } @@ -615,6 +622,7 @@ func (f *formatFMP4) initialize() bool { forma, func(u unit.Unit) error { tunit := u.(*unit.Opus) + if tunit.Packets == nil { return nil } @@ -651,6 +659,7 @@ func (f *formatFMP4) initialize() bool { forma, func(u unit.Unit) error { tunit := u.(*unit.MPEG4Audio) + if tunit.AUs == nil { return nil } @@ -686,6 +695,7 @@ func (f *formatFMP4) initialize() bool { forma, func(u unit.Unit) error { tunit := u.(*unit.MPEG4AudioLATM) + if tunit.Element == nil { return nil } @@ -722,6 +732,7 @@ func (f *formatFMP4) initialize() bool { forma, func(u unit.Unit) error { tunit := u.(*unit.MPEG1Audio) + if tunit.Frames == nil { return nil } @@ -781,6 +792,7 @@ func (f *formatFMP4) initialize() bool { forma, func(u unit.Unit) error { tunit := u.(*unit.AC3) + if tunit.Frames == nil { return nil } @@ -886,6 +898,7 @@ func (f *formatFMP4) initialize() bool { forma, func(u unit.Unit) error { tunit := u.(*unit.LPCM) + if tunit.Samples == nil { return nil } diff --git a/internal/recorder/format_fmp4_track.go b/internal/recorder/format_fmp4_track.go index 0ed3aa39..fe3b5f0f 100644 --- a/internal/recorder/format_fmp4_track.go +++ b/internal/recorder/format_fmp4_track.go @@ -84,7 +84,7 @@ func (t *formatFMP4Track) write(sample *sample) error { if (!t.f.hasVideo || t.initTrack.Codec.IsVideo()) && !t.nextSample.IsNonSyncSample && (nextDTS-t.f.currentSegment.startDTS) >= t.f.ri.segmentDuration { - err := t.f.currentSegment.close() + err = t.f.currentSegment.close() if err != nil { return err } diff --git a/internal/recorder/format_mpegts.go b/internal/recorder/format_mpegts.go index 655b0113..e5000ceb 100644 --- a/internal/recorder/format_mpegts.go +++ b/internal/recorder/format_mpegts.go @@ -94,6 +94,7 @@ func (f *formatMPEGTS) initialize() bool { forma, func(u unit.Unit) error { tunit := u.(*unit.H265) + if tunit.AU == nil { return nil } @@ -139,6 +140,7 @@ func (f *formatMPEGTS) initialize() bool { forma, func(u unit.Unit) error { tunit := u.(*unit.H264) + if tunit.AU == nil { return nil } @@ -185,6 +187,7 @@ func (f *formatMPEGTS) initialize() bool { forma, func(u unit.Unit) error { tunit := u.(*unit.MPEG4Video) + if tunit.Frame == nil { return nil } @@ -224,6 +227,7 @@ func (f *formatMPEGTS) initialize() bool { forma, func(u unit.Unit) error { tunit := u.(*unit.MPEG1Video) + if tunit.Frame == nil { return nil } @@ -262,6 +266,7 @@ func (f *formatMPEGTS) initialize() bool { forma, func(u unit.Unit) error { tunit := u.(*unit.Opus) + if tunit.Packets == nil { return nil } @@ -291,6 +296,7 @@ func (f *formatMPEGTS) initialize() bool { forma, func(u unit.Unit) error { tunit := u.(*unit.KLV) + if tunit.Unit == nil { return nil } @@ -317,6 +323,7 @@ func (f *formatMPEGTS) initialize() bool { forma, func(u unit.Unit) error { tunit := u.(*unit.MPEG4Audio) + if tunit.AUs == nil { return nil } @@ -347,6 +354,7 @@ func (f *formatMPEGTS) initialize() bool { forma, func(u unit.Unit) error { tunit := u.(*unit.MPEG4AudioLATM) + if tunit.Element == nil { return nil } @@ -382,6 +390,7 @@ func (f *formatMPEGTS) initialize() bool { forma, func(u unit.Unit) error { tunit := u.(*unit.MPEG1Audio) + if tunit.Frames == nil { return nil } @@ -409,6 +418,7 @@ func (f *formatMPEGTS) initialize() bool { forma, func(u unit.Unit) error { tunit := u.(*unit.AC3) + if tunit.Frames == nil { return nil } diff --git a/internal/recordstore/segment.go b/internal/recordstore/segment.go index 643d1170..e4972069 100644 --- a/internal/recordstore/segment.go +++ b/internal/recordstore/segment.go @@ -78,7 +78,7 @@ func regexpPathFindPathsWithSegments(pathConf *conf.Path) map[string]struct{} { if !info.IsDir() { var pa Path if ok := pa.Decode(recordPath, fpath); ok { - if err := conf.IsValidPathName(pa.Path); err == nil { + if err = conf.IsValidPathName(pa.Path); err == nil { if pathConf.Regexp.FindStringSubmatch(pa.Path) != nil { ret[pa.Path] = struct{}{} } diff --git a/internal/servers/hls/http_server.go b/internal/servers/hls/http_server.go index cdf04b00..7616355f 100644 --- a/internal/servers/hls/http_server.go +++ b/internal/servers/hls/http_server.go @@ -187,7 +187,8 @@ func (s *httpServer) onRequest(ctx *gin.Context) { ctx.Writer.Write(hlsIndex) default: - mux, err := s.parent.getMuxer(serverGetMuxerReq{ + var mux *muxer + mux, err = s.parent.getMuxer(serverGetMuxerReq{ path: dir, remoteAddr: httpp.RemoteAddr(ctx), query: ctx.Request.URL.RawQuery, diff --git a/internal/servers/hls/muxer.go b/internal/servers/hls/muxer.go index 5806133c..181bd1a0 100644 --- a/internal/servers/hls/muxer.go +++ b/internal/servers/hls/muxer.go @@ -184,7 +184,7 @@ func (m *muxer) runInner() error { case req := <-m.chGetInstance: req.res <- mi - case err := <-instanceError: + case err = <-instanceError: if m.remoteAddr != "" { return err } @@ -208,7 +208,7 @@ func (m *muxer) runInner() error { bytesSent: m.bytesSent, parent: m, } - err := mi.initialize() + err = mi.initialize() if err != nil { m.Log(logger.Error, err.Error()) mi = nil diff --git a/internal/servers/hls/server_test.go b/internal/servers/hls/server_test.go index 9942f8da..3d843b77 100644 --- a/internal/servers/hls/server_test.go +++ b/internal/servers/hls/server_test.go @@ -144,20 +144,24 @@ func TestServerNotFound(t *testing.T) { hc := &http.Client{Transport: tr} func() { - req, err := http.NewRequest(http.MethodGet, "http://myuser:mypass@127.0.0.1:8888/nonexisting/", nil) + var req *http.Request + req, err = http.NewRequest(http.MethodGet, "http://myuser:mypass@127.0.0.1:8888/nonexisting/", nil) require.NoError(t, err) - res, err := hc.Do(req) + var res *http.Response + res, err = hc.Do(req) require.NoError(t, err) defer res.Body.Close() require.Equal(t, http.StatusOK, res.StatusCode) }() func() { - req, err := http.NewRequest(http.MethodGet, "http://myuser:mypass@127.0.0.1:8888/nonexisting/index.m3u8", nil) + var req *http.Request + req, err = http.NewRequest(http.MethodGet, "http://myuser:mypass@127.0.0.1:8888/nonexisting/index.m3u8", nil) require.NoError(t, err) - res, err := hc.Do(req) + var res *http.Response + res, err = hc.Do(req) require.NoError(t, err) defer res.Body.Close() require.Equal(t, http.StatusNotFound, res.StatusCode) diff --git a/internal/servers/rtmp/conn.go b/internal/servers/rtmp/conn.go index adc726bf..090ecfdf 100644 --- a/internal/servers/rtmp/conn.go +++ b/internal/servers/rtmp/conn.go @@ -210,7 +210,7 @@ func (c *conn) runRead() error { case <-c.ctx.Done(): return fmt.Errorf("terminated") - case err := <-stream.ReaderError(c): + case err = <-stream.ReaderError(c): return err } } @@ -275,7 +275,7 @@ func (c *conn) runPublish() error { for { c.nconn.SetReadDeadline(time.Now().Add(time.Duration(c.readTimeout))) - err := r.Read() + err = r.Read() if err != nil { return err } diff --git a/internal/servers/srt/conn.go b/internal/servers/srt/conn.go index 806da29f..61b9efeb 100644 --- a/internal/servers/srt/conn.go +++ b/internal/servers/srt/conn.go @@ -174,7 +174,7 @@ func (c *conn) runPublish(streamID *streamID) error { }() select { - case err := <-readerErr: + case err = <-readerErr: sconn.Close() return err diff --git a/internal/servers/webrtc/session.go b/internal/servers/webrtc/session.go index ba98c357..92de5121 100644 --- a/internal/servers/webrtc/session.go +++ b/internal/servers/webrtc/session.go @@ -356,7 +356,7 @@ func (s *session) runRead() (int, error) { case <-pc.Failed(): return 0, fmt.Errorf("peer connection closed") - case err := <-stream.ReaderError(s): + case err = <-stream.ReaderError(s): return 0, err case <-s.ctx.Done(): diff --git a/internal/staticsources/hls/source.go b/internal/staticsources/hls/source.go index 432a1f89..710db16d 100644 --- a/internal/staticsources/hls/source.go +++ b/internal/staticsources/hls/source.go @@ -113,7 +113,7 @@ func (s *Source) Run(params defs.StaticSourceRunParams) error { for { select { - case err := <-waitErr: + case err = <-waitErr: c.Close() return err diff --git a/internal/staticsources/rpicamera/mtxrpicamdownloader/main.go b/internal/staticsources/rpicamera/mtxrpicamdownloader/main.go index 62afd5fe..412e7942 100644 --- a/internal/staticsources/rpicamera/mtxrpicamdownloader/main.go +++ b/internal/staticsources/rpicamera/mtxrpicamdownloader/main.go @@ -25,7 +25,8 @@ func dumpTar(src io.Reader) error { tr := tar.NewReader(uncompressed) for { - header, err := tr.Next() + var header *tar.Header + header, err = tr.Next() if err != nil { if errors.Is(err, io.EOF) { break @@ -41,7 +42,8 @@ func dumpTar(src io.Reader) error { } case tar.TypeReg: - f, err := os.OpenFile(header.Name, os.O_WRONLY|os.O_CREATE, header.FileInfo().Mode()) + var f *os.File + f, err = os.OpenFile(header.Name, os.O_WRONLY|os.O_CREATE, header.FileInfo().Mode()) if err != nil { return err } diff --git a/internal/staticsources/rpicamera/source.go b/internal/staticsources/rpicamera/source.go index 9d9dc5a4..b611a6b5 100644 --- a/internal/staticsources/rpicamera/source.go +++ b/internal/staticsources/rpicamera/source.go @@ -243,7 +243,7 @@ func (s *Source) runPrimary(params defs.StaticSourceRunParams) error { for { select { - case err := <-cameraErr: + case err = <-cameraErr: return err case cnf := <-params.ReloadConf: @@ -301,7 +301,7 @@ func (s *Source) runSecondary(params defs.StaticSourceRunParams) error { defer origStream.RemoveReader(s) select { - case err := <-origStream.ReaderError(s): + case err = <-origStream.ReaderError(s): return err case <-r.ctx.Done(): diff --git a/internal/staticsources/rtmp/source.go b/internal/staticsources/rtmp/source.go index 35d96df8..5dfc5a63 100644 --- a/internal/staticsources/rtmp/source.go +++ b/internal/staticsources/rtmp/source.go @@ -58,7 +58,7 @@ func (s *Source) Run(params defs.StaticSourceRunParams) error { for { select { - case err := <-readDone: + case err = <-readDone: ctxCancel() return err @@ -124,9 +124,9 @@ func (s *Source) runReader(ctx context.Context, u *url.URL, fingerprint string) go func() { for { conn.NetConn().SetReadDeadline(time.Now().Add(time.Duration(s.ReadTimeout))) - err := r.Read() - if err != nil { - readerErr <- err + err2 := r.Read() + if err2 != nil { + readerErr <- err2 return } } @@ -138,7 +138,7 @@ func (s *Source) runReader(ctx context.Context, u *url.URL, fingerprint string) <-readerErr return fmt.Errorf("terminated") - case err := <-readerErr: + case err = <-readerErr: return err } } diff --git a/internal/staticsources/rtsp/source.go b/internal/staticsources/rtsp/source.go index 7171cad3..e635474e 100644 --- a/internal/staticsources/rtsp/source.go +++ b/internal/staticsources/rtsp/source.go @@ -150,14 +150,14 @@ func (s *Source) Run(params defs.StaticSourceRunParams) error { readErr := make(chan error) go func() { readErr <- func() error { - desc, _, err := c.Describe(u) - if err != nil { - return err + desc, _, err2 := c.Describe(u) + if err2 != nil { + return err2 } - err = c.SetupAll(desc.BaseURL, desc.Medias) - if err != nil { - return err + err2 = c.SetupAll(desc.BaseURL, desc.Medias) + if err2 != nil { + return err2 } res := s.Parent.SetReady(defs.PathSourceStaticSetReadyReq{ @@ -177,14 +177,14 @@ func (s *Source) Run(params defs.StaticSourceRunParams) error { res.Stream, s) - rangeHeader, err := createRangeHeader(params.Conf) - if err != nil { - return err + rangeHeader, err2 := createRangeHeader(params.Conf) + if err2 != nil { + return err2 } - _, err = c.Play(rangeHeader) - if err != nil { - return err + _, err2 = c.Play(rangeHeader) + if err2 != nil { + return err2 } return c.Wait() @@ -193,7 +193,7 @@ func (s *Source) Run(params defs.StaticSourceRunParams) error { for { select { - case err := <-readErr: + case err = <-readErr: return err case <-params.ReloadConf: diff --git a/internal/staticsources/srt/source.go b/internal/staticsources/srt/source.go index f41405db..ff3b677a 100644 --- a/internal/staticsources/srt/source.go +++ b/internal/staticsources/srt/source.go @@ -53,7 +53,7 @@ func (s *Source) Run(params defs.StaticSourceRunParams) error { for { select { - case err := <-readDone: + case err = <-readDone: sconn.Close() return err @@ -116,7 +116,7 @@ func (s *Source) runReader(sconn srt.Conn) error { for { sconn.SetReadDeadline(time.Now().Add(time.Duration(s.ReadTimeout))) - err := r.Read() + err = r.Read() if err != nil { return err } diff --git a/internal/staticsources/srt/source_test.go b/internal/staticsources/srt/source_test.go index c84854e3..652a4b86 100644 --- a/internal/staticsources/srt/source_test.go +++ b/internal/staticsources/srt/source_test.go @@ -20,15 +20,15 @@ func TestSource(t *testing.T) { defer ln.Close() go func() { - req, err := ln.Accept2() - require.NoError(t, err) + req, err2 := ln.Accept2() + require.NoError(t, err2) require.Equal(t, "sidname", req.StreamId()) - err = req.SetPassphrase("ttest1234567") - require.NoError(t, err) + err2 = req.SetPassphrase("ttest1234567") + require.NoError(t, err2) - conn, err := req.Accept() - require.NoError(t, err) + conn, err2 := req.Accept() + require.NoError(t, err2) defer conn.Close() track := &mpegts.Track{ @@ -37,16 +37,16 @@ func TestSource(t *testing.T) { bw := bufio.NewWriter(conn) w := &mpegts.Writer{W: bw, Tracks: []*mpegts.Track{track}} - err = w.Initialize() - require.NoError(t, err) + err2 = w.Initialize() + require.NoError(t, err2) - err = w.WriteH264(track, 0, 0, [][]byte{{ // IDR + err2 = w.WriteH264(track, 0, 0, [][]byte{{ // IDR 5, 1, }}) - require.NoError(t, err) + require.NoError(t, err2) - err = bw.Flush() - require.NoError(t, err) + err2 = bw.Flush() + require.NoError(t, err2) // wait for internal SRT queue to be written time.Sleep(500 * time.Millisecond) diff --git a/internal/staticsources/udp/source.go b/internal/staticsources/udp/source.go index 80923cc9..9475ea83 100644 --- a/internal/staticsources/udp/source.go +++ b/internal/staticsources/udp/source.go @@ -123,7 +123,7 @@ func (s *Source) Run(params defs.StaticSourceRunParams) error { }() select { - case err := <-readerErr: + case err = <-readerErr: return err case <-params.Context.Done(): @@ -183,7 +183,7 @@ func (s *Source) runReader(pc net.PacketConn, sourceIP net.IP) error { for { pc.SetReadDeadline(time.Now().Add(time.Duration(s.ReadTimeout))) - err := r.Read() + err = r.Read() if err != nil { return err } diff --git a/internal/stream/stream.go b/internal/stream/stream.go index acbffae2..99c558a7 100644 --- a/internal/stream/stream.go +++ b/internal/stream/stream.go @@ -236,7 +236,7 @@ func (s *Stream) ReaderFormats(reader Reader) []format.Format { for forma, sf := range sm.formats { if _, ok := sf.pausedReaders[sr]; ok { formats = append(formats, forma) - } else if _, ok := sf.runningReaders[sr]; ok { + } else if _, ok = sf.runningReaders[sr]; ok { formats = append(formats, forma) } }