diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index e36879cf..8ce778d8 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -26,7 +26,7 @@ jobs: - uses: golangci/golangci-lint-action@v9 with: - version: v2.12.2 + version: v2.13.1 go_mod: runs-on: ubuntu-24.04 diff --git a/internal/auth/manager.go b/internal/auth/manager.go index d1e2dbdd..e49425e7 100644 --- a/internal/auth/manager.go +++ b/internal/auth/manager.go @@ -295,7 +295,7 @@ func (m *Manager) pullJWTJWKS() (jwt.Keyfunc, error) { defer tr.CloseIdleConnections() httpClient := &http.Client{ - Timeout: (m.ReadTimeout), + Timeout: m.ReadTimeout, Transport: tr, } diff --git a/internal/conf/env/env.go b/internal/conf/env/env.go index b000b667..6e93ab8d 100644 --- a/internal/conf/env/env.go +++ b/internal/conf/env/env.go @@ -30,7 +30,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 i, ok := reflect.TypeAssert[Unmarshaler](prv); ok { if ev, ok2 := env[prefix]; ok2 { if prv.IsNil() { prv.Set(reflect.New(rt)) @@ -124,8 +124,8 @@ func loadEnvInternal(env map[string]string, prefix string, prv reflect.Value) er continue } - mapKey := strings.Split(k[len(prefix+"_"):], "_")[0] - if len(mapKey) == 0 { + mapKey, _, _ := strings.Cut(k[len(prefix+"_"):], "_") + if mapKey == "" { continue } diff --git a/internal/conf/jsonwrapper/unmarshal.go b/internal/conf/jsonwrapper/unmarshal.go index 0e7e16d0..1ffd3135 100644 --- a/internal/conf/jsonwrapper/unmarshal.go +++ b/internal/conf/jsonwrapper/unmarshal.go @@ -60,7 +60,7 @@ func decode(v reflect.Value, raw json.RawMessage, path string) error { v = v.Elem() } - if unm, ok := v.Addr().Interface().(json.Unmarshaler); ok { + if unm, ok := reflect.TypeAssert[json.Unmarshaler](v.Addr()); ok { return unm.UnmarshalJSON(raw) } diff --git a/internal/ntpestimator/estimator.go b/internal/ntpestimator/estimator.go index 6a6c5c5c..ec69a25e 100644 --- a/internal/ntpestimator/estimator.go +++ b/internal/ntpestimator/estimator.go @@ -41,7 +41,7 @@ func (e *Estimator) Estimate(pts int64) time.Time { return now } - computed := e.refNTP.Add((multiplyAndDivide(time.Duration(pts-e.refPTS), time.Second, time.Duration(e.ClockRate)))) + computed := e.refNTP.Add(multiplyAndDivide(time.Duration(pts-e.refPTS), time.Second, time.Duration(e.ClockRate))) if computed.After(now) || computed.Before(now.Add(-maxTimeDifference)) { e.refNTP = now diff --git a/internal/playback/on_get_test.go b/internal/playback/on_get_test.go index 0f9e1ce7..8abb86b5 100644 --- a/internal/playback/on_get_test.go +++ b/internal/playback/on_get_test.go @@ -40,9 +40,10 @@ func writeSegment1(t *testing.T, fpath string) { TimeScale: 48000, Codec: &mcodecs.MPEG4Audio{ Config: mpeg4audio.AudioSpecificConfig{ - Type: mpeg4audio.ObjectTypeAACLC, - SampleRate: 48000, - ChannelCount: 2, + Type: mpeg4audio.ObjectTypeAACLC, + SampleRate: 48000, + ChannelCount: 2, //nolint:staticcheck + ChannelConfig: 2, }, }, }, @@ -118,9 +119,10 @@ func writeSegment2(t *testing.T, fpath string) { TimeScale: 48000, Codec: &mcodecs.MPEG4Audio{ Config: mpeg4audio.AudioSpecificConfig{ - Type: mpeg4audio.ObjectTypeAACLC, - SampleRate: 48000, - ChannelCount: 2, + Type: mpeg4audio.ObjectTypeAACLC, + SampleRate: 48000, + ChannelConfig: 2, + ChannelCount: 2, //nolint:staticcheck }, }, }, @@ -260,9 +262,10 @@ func TestOnGet(t *testing.T) { TimeScale: 48000, Codec: &mcodecs.MPEG4Audio{ Config: mpeg4audio.AudioSpecificConfig{ - Type: mpeg4audio.ObjectTypeAACLC, - SampleRate: 48000, - ChannelCount: 2, + Type: mpeg4audio.ObjectTypeAACLC, + SampleRate: 48000, + ChannelCount: 2, //nolint:staticcheck + ChannelConfig: 2, }, }, }, @@ -662,7 +665,7 @@ func TestOnGet(t *testing.T) { Config: mpeg4audio.AudioSpecificConfig{ Type: mpeg4audio.ObjectTypeAACLC, SampleRate: 48000, - ChannelCount: 2, + ChannelCount: 2, //nolint:staticcheck ChannelConfig: 2, }, }, diff --git a/internal/playback/segment_fmp4_test.go b/internal/playback/segment_fmp4_test.go index fd7b7f53..0b91e34c 100644 --- a/internal/playback/segment_fmp4_test.go +++ b/internal/playback/segment_fmp4_test.go @@ -32,9 +32,10 @@ func writeBenchInit(f io.WriteSeeker) { TimeScale: 90000, Codec: &mcodecs.MPEG4Audio{ Config: mpeg4audio.AudioSpecificConfig{ - Type: mpeg4audio.ObjectTypeAACLC, - SampleRate: 48000, - ChannelCount: 2, + Type: mpeg4audio.ObjectTypeAACLC, + SampleRate: 48000, + ChannelCount: 2, //nolint:staticcheck + ChannelConfig: 2, }, }, }, @@ -98,9 +99,10 @@ func TestSegmentFMP4CanBeConcatenated(t *testing.T) { TimeScale: 48000, Codec: &mcodecs.MPEG4Audio{ Config: mpeg4audio.AudioSpecificConfig{ - Type: mpeg4audio.ObjectTypeAACLC, - SampleRate: 48000, - ChannelCount: 2, + Type: mpeg4audio.ObjectTypeAACLC, + SampleRate: 48000, + ChannelConfig: 2, + ChannelCount: 2, //nolint:staticcheck }, }, }, @@ -406,9 +408,10 @@ func TestSegmentFMP4CanBeConcatenated(t *testing.T) { TimeScale: 90000, Codec: &mcodecs.MPEG4Audio{ Config: mpeg4audio.AudioSpecificConfig{ - Type: mpeg4audio.ObjectTypeAACLC, - SampleRate: 48000, - ChannelCount: 2, + Type: mpeg4audio.ObjectTypeAACLC, + SampleRate: 48000, + ChannelConfig: 2, + ChannelCount: 2, //nolint:staticcheck }, }, }, diff --git a/internal/protocols/mpegts/to_stream_test.go b/internal/protocols/mpegts/to_stream_test.go index 435704a5..7fd53ffb 100644 --- a/internal/protocols/mpegts/to_stream_test.go +++ b/internal/protocols/mpegts/to_stream_test.go @@ -66,9 +66,10 @@ func TestToStream(t *testing.T) { Programs: []*mpeg4audio.StreamMuxConfigProgram{{ Layers: []*mpeg4audio.StreamMuxConfigLayer{{ AudioSpecificConfig: &mpeg4audio.AudioSpecificConfig{ - Type: 2, - SampleRate: 48000, - ChannelCount: 2, + Type: 2, + SampleRate: 48000, + ChannelConfig: 2, + ChannelCount: 2, //nolint:staticcheck }, LatmBufferFullness: 255, }}, @@ -137,7 +138,7 @@ func TestToStream(t *testing.T) { AudioSpecificConfig: &mpeg4audio.AudioSpecificConfig{ Type: 2, SampleRate: 48000, - ChannelCount: 2, + ChannelCount: 2, //nolint:staticcheck ChannelConfig: 2, }, LatmBufferFullness: 255, diff --git a/internal/protocols/proxy/listener.go b/internal/protocols/proxy/listener.go index 98d6b5b8..3d2e9e48 100644 --- a/internal/protocols/proxy/listener.go +++ b/internal/protocols/proxy/listener.go @@ -23,8 +23,8 @@ type Listener struct { func (l *Listener) Initialize() { l.inner = &proxyproto.Listener{ Listener: l.Wrapped, - Policy: func(upstream net.Addr) (proxyproto.Policy, error) { - tcpAddr, ok := upstream.(*net.TCPAddr) + ConnPolicy: func(connPolicyOptions proxyproto.ConnPolicyOptions) (proxyproto.Policy, error) { + tcpAddr, ok := connPolicyOptions.Upstream.(*net.TCPAddr) if ok && l.TrustedProxies.Contains(tcpAddr.IP) { return proxyproto.USE, nil } diff --git a/internal/protocols/proxy/listener_test.go b/internal/protocols/proxy/listener_test.go index c1dfc76a..9338ff4d 100644 --- a/internal/protocols/proxy/listener_test.go +++ b/internal/protocols/proxy/listener_test.go @@ -1,4 +1,4 @@ -package proxy +package proxy_test import ( "fmt" @@ -9,6 +9,7 @@ import ( "github.com/stretchr/testify/require" "github.com/bluenviron/mediamtx/internal/conf" + "github.com/bluenviron/mediamtx/internal/protocols/proxy" ) func trustedProxies(cidrs ...string) conf.IPNetworks { @@ -30,7 +31,7 @@ func TestListenerTrustedWithHeader(t *testing.T) { require.NoError(t, err) defer ln.Close() - wrapped := &Listener{Wrapped: ln, TrustedProxies: trustedProxies("127.0.0.1/32")} + wrapped := &proxy.Listener{Wrapped: ln, TrustedProxies: trustedProxies("127.0.0.1/32")} wrapped.Initialize() done := make(chan struct{}) @@ -69,7 +70,7 @@ func TestListenerTrustedWithoutHeader(t *testing.T) { require.NoError(t, err) defer ln.Close() - wrapped := &Listener{Wrapped: ln, TrustedProxies: trustedProxies("127.0.0.1/32")} + wrapped := &proxy.Listener{Wrapped: ln, TrustedProxies: trustedProxies("127.0.0.1/32")} wrapped.Initialize() done := make(chan struct{}) @@ -102,7 +103,7 @@ func TestListenerUntrustedIgnoresHeader(t *testing.T) { require.NoError(t, err) defer ln.Close() - wrapped := &Listener{Wrapped: ln, TrustedProxies: trustedProxies("10.0.0.0/8")} + wrapped := &proxy.Listener{Wrapped: ln, TrustedProxies: trustedProxies("10.0.0.0/8")} wrapped.Initialize() done := make(chan struct{}) diff --git a/internal/protocols/rtmp/from_stream_test.go b/internal/protocols/rtmp/from_stream_test.go index 2c9d3118..4574593c 100644 --- a/internal/protocols/rtmp/from_stream_test.go +++ b/internal/protocols/rtmp/from_stream_test.go @@ -710,7 +710,7 @@ func TestFromStreamLegacyClientMultipleTracks(t *testing.T) { aacConfig2 := &mpeg4audio.AudioSpecificConfig{ Type: 2, // MPEG4-AAC LC SampleRate: 48000, - ChannelCount: 2, + ChannelCount: 2, //nolint:staticcheck ChannelConfig: 2, } diff --git a/internal/recorder/format_fmp4.go b/internal/recorder/format_fmp4.go index 43b32633..90820ac4 100644 --- a/internal/recorder/format_fmp4.go +++ b/internal/recorder/format_fmp4.go @@ -772,7 +772,6 @@ func (f *formatFMP4) initialize() bool { codec := &mcodecs.AC3{ SampleRate: origFormat.SampleRate, ChannelCount: origFormat.ChannelCount, - Fscod: 0, Bsid: 8, Bsmod: 0, Acmod: 7, diff --git a/internal/recorder/format_mpegts.go b/internal/recorder/format_mpegts.go index 675ec5ae..8658702b 100644 --- a/internal/recorder/format_mpegts.go +++ b/internal/recorder/format_mpegts.go @@ -16,6 +16,7 @@ import ( "github.com/bluenviron/mediacommon/v2/pkg/codecs/mpeg4video" "github.com/bluenviron/mediacommon/v2/pkg/formats/mpegts" tscodecs "github.com/bluenviron/mediacommon/v2/pkg/formats/mpegts/codecs" + "github.com/bluenviron/mediacommon/v2/pkg/formats/mpegts/substructs" "github.com/bluenviron/mediamtx/internal/defs" "github.com/bluenviron/mediamtx/internal/formatlabel" @@ -243,7 +244,9 @@ func (f *formatMPEGTS) initialize() bool { case *rtspformat.Opus: track := addTrack(&tscodecs.Opus{ - ChannelCount: forma.ChannelCount, + Desc: &substructs.OpusAudioDescriptor{ + ChannelConfigCode: 2, + }, }) f.ri.reader.OnData( diff --git a/internal/recorder/recorder_test.go b/internal/recorder/recorder_test.go index 3ab81192..86c7a075 100644 --- a/internal/recorder/recorder_test.go +++ b/internal/recorder/recorder_test.go @@ -43,9 +43,10 @@ func TestRecorder(t *testing.T) { Formats: []rtspformat.Format{&rtspformat.MPEG4Audio{ PayloadTyp: 96, Config: &mpeg4audio.AudioSpecificConfig{ - Type: 2, - SampleRate: 44100, - ChannelCount: 2, + Type: 2, + SampleRate: 44100, + ChannelConfig: 2, + ChannelCount: 2, //nolint:staticcheck }, SizeLength: 13, IndexLength: 3, @@ -280,7 +281,7 @@ func TestRecorder(t *testing.T) { Config: mpeg4audio.AudioSpecificConfig{ Type: 2, SampleRate: 44100, - ChannelCount: 2, + ChannelCount: 2, //nolint:staticcheck ChannelConfig: 2, }, }, @@ -411,9 +412,10 @@ func TestRecorderFMP4NegativeInitialDTS(t *testing.T) { Formats: []rtspformat.Format{&rtspformat.MPEG4Audio{ PayloadTyp: 96, Config: &mpeg4audio.AudioSpecificConfig{ - Type: 2, - SampleRate: 44100, - ChannelCount: 2, + Type: 2, + SampleRate: 44100, + ChannelConfig: 2, + ChannelCount: 2, //nolint:staticcheck }, SizeLength: 13, IndexLength: 3, @@ -504,9 +506,10 @@ func TestRecorderFMP4NegativeDTSDiff(t *testing.T) { Formats: []rtspformat.Format{&rtspformat.MPEG4Audio{ PayloadTyp: 96, Config: &mpeg4audio.AudioSpecificConfig{ - Type: 2, - SampleRate: 44100, - ChannelCount: 2, + Type: 2, + SampleRate: 44100, + ChannelConfig: 2, + ChannelCount: 2, //nolint:staticcheck }, SizeLength: 13, IndexLength: 3, @@ -863,9 +866,10 @@ func TestRecorderTimeDriftDetector(t *testing.T) { Formats: []rtspformat.Format{&rtspformat.MPEG4Audio{ PayloadTyp: 96, Config: &mpeg4audio.AudioSpecificConfig{ - Type: 2, - SampleRate: 44100, - ChannelCount: 2, + Type: 2, + SampleRate: 44100, + ChannelConfig: 2, + ChannelCount: 2, //nolint:staticcheck }, SizeLength: 13, IndexLength: 3, diff --git a/internal/servers/hls/server_test.go b/internal/servers/hls/server_test.go index 094ce5d2..f5947641 100644 --- a/internal/servers/hls/server_test.go +++ b/internal/servers/hls/server_test.go @@ -397,7 +397,7 @@ func TestServerRead(t *testing.T) { Codec: &codecs.MPEG4Audio{ Config: mpeg4audio.AudioSpecificConfig{ Type: 2, - ChannelCount: 2, + ChannelCount: 2, //nolint:staticcheck ChannelConfig: 2, SampleRate: 44100, }, diff --git a/internal/servers/rtmp/server.go b/internal/servers/rtmp/server.go index c1e46e59..38b47894 100644 --- a/internal/servers/rtmp/server.go +++ b/internal/servers/rtmp/server.go @@ -238,7 +238,7 @@ func (s *Server) Log(level logger.Level, format string, args ...any) { func (s *Server) Close() { s.Log(logger.Info, "closing") - if !interfaceIsEmpty((s.Metrics)) { + if !interfaceIsEmpty(s.Metrics) { if s.Encryption { s.Metrics.SetRTMPSServer(nil) } else { diff --git a/internal/staticsources/hls/source_test.go b/internal/staticsources/hls/source_test.go index f7c9c675..0b91c58f 100644 --- a/internal/staticsources/hls/source_test.go +++ b/internal/staticsources/hls/source_test.go @@ -25,9 +25,10 @@ func TestSource(t *testing.T) { track2 := &mpegts.Track{ Codec: &tscodecs.MPEG4Audio{ Config: mpeg4audio.AudioSpecificConfig{ - Type: 2, - SampleRate: 44100, - ChannelCount: 2, + Type: 2, + SampleRate: 44100, + ChannelConfig: 2, + ChannelCount: 2, //nolint:staticcheck }, }, } diff --git a/internal/stream/stream.go b/internal/stream/stream.go index 7b679dbd..671c2f04 100644 --- a/internal/stream/stream.go +++ b/internal/stream/stream.go @@ -182,7 +182,7 @@ func mediasFromAlwaysAvailableTracks(alwaysAvailableTracks []conf.AlwaysAvailabl Type: mpeg4audio.ObjectTypeAACLC, SampleRate: track.SampleRate, ChannelConfig: uint8(track.ChannelCount), - ChannelCount: track.ChannelCount, + ChannelCount: track.ChannelCount, //nolint:staticcheck }, }}, }) diff --git a/internal/stream/stream_test.go b/internal/stream/stream_test.go index 67bdf91f..79a1d719 100644 --- a/internal/stream/stream_test.go +++ b/internal/stream/stream_test.go @@ -520,7 +520,7 @@ func TestStreamAlwaysAvailable(t *testing.T) { Type: 2, SampleRate: 44100, ChannelConfig: 2, - ChannelCount: 2, + ChannelCount: 2, //nolint:staticcheck }, }, Samples: []*pmp4.Sample{ @@ -768,7 +768,7 @@ func TestStreamAlwaysAvailable(t *testing.T) { Type: 2, SampleRate: 44100, ChannelConfig: 2, - ChannelCount: 2, + ChannelCount: 2, //nolint:staticcheck }, }}, }, diff --git a/internal/test/formats.go b/internal/test/formats.go index fc4234a4..bd14a3ae 100644 --- a/internal/test/formats.go +++ b/internal/test/formats.go @@ -46,7 +46,7 @@ var FormatMPEG4Audio = &format.MPEG4Audio{ Config: &mpeg4audio.AudioSpecificConfig{ Type: 2, SampleRate: 44100, - ChannelCount: 2, + ChannelCount: 2, //nolint:staticcheck ChannelConfig: 2, }, SizeLength: 13,