diff --git a/go.mod b/go.mod index eefd1698be0..6e37b548927 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/abema/go-mp4 v1.2.0 github.com/alecthomas/kong v0.9.0 github.com/bluenviron/gohlslib v1.3.2 - github.com/bluenviron/gortsplib/v4 v4.9.1-0.20240515082130-f283abc2e7cd + github.com/bluenviron/gortsplib/v4 v4.9.1-0.20240518103134-27831ced0c04 github.com/bluenviron/mediacommon v1.10.1-0.20240518092051-bab50c4ba9c5 github.com/datarhei/gosrt v0.6.0 github.com/fsnotify/fsnotify v1.7.0 diff --git a/go.sum b/go.sum index 694d9eda775..9f9cbbab61f 100644 --- a/go.sum +++ b/go.sum @@ -22,8 +22,8 @@ github.com/benburkert/openpgp v0.0.0-20160410205803-c2471f86866c h1:8XZeJrs4+ZYh github.com/benburkert/openpgp v0.0.0-20160410205803-c2471f86866c/go.mod h1:x1vxHcL/9AVzuk5HOloOEPrtJY0MaalYr78afXZ+pWI= github.com/bluenviron/gohlslib v1.3.2 h1:xRiPfMIeYCkspL6jYa7Qrl4pIY+1w7IvFjx49CsyfKY= github.com/bluenviron/gohlslib v1.3.2/go.mod h1:1/m7A2o5IWyBdZeauXe2bViu2l1mL2l8DMQl9302A2U= -github.com/bluenviron/gortsplib/v4 v4.9.1-0.20240515082130-f283abc2e7cd h1:w1Uml4bXdixu7cArQ3JyiZTpaKzZ31eP9+bWoPPkWcY= -github.com/bluenviron/gortsplib/v4 v4.9.1-0.20240515082130-f283abc2e7cd/go.mod h1:iLJ1tmwGMbaN04ZYh/KRlAHsCbz9Rycn7cPAvdR+Vkc= +github.com/bluenviron/gortsplib/v4 v4.9.1-0.20240518103134-27831ced0c04 h1:r0O2Dl6g31cjpuPnjWMbvjY5z9AIoaftLW4328yJdXc= +github.com/bluenviron/gortsplib/v4 v4.9.1-0.20240518103134-27831ced0c04/go.mod h1:iLJ1tmwGMbaN04ZYh/KRlAHsCbz9Rycn7cPAvdR+Vkc= github.com/bluenviron/mediacommon v1.10.1-0.20240518092051-bab50c4ba9c5 h1:fZL+8Bz8wT0ljvt+ZyGGzirT1jQxH1wgqOiyRifAL60= github.com/bluenviron/mediacommon v1.10.1-0.20240518092051-bab50c4ba9c5/go.mod h1:HDyW2CzjvhYJXtdxstdFPio3G0qSocPhqkhUt/qffec= github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0= diff --git a/internal/protocols/mpegts/from_stream.go b/internal/protocols/mpegts/from_stream.go index b1a91344de5..48989aff02b 100644 --- a/internal/protocols/mpegts/from_stream.go +++ b/internal/protocols/mpegts/from_stream.go @@ -165,12 +165,7 @@ func FromStream( case *format.Opus: track := addTrack(&mcmpegts.CodecOpus{ - ChannelCount: func() int { - if forma.IsStereo { - return 2 - } - return 1 - }(), + ChannelCount: forma.ChannelCount, }) stream.AddReader(writer, medi, forma, func(u unit.Unit) error { diff --git a/internal/protocols/mpegts/to_stream.go b/internal/protocols/mpegts/to_stream.go index 4c4ff57fa7a..d3c17228293 100644 --- a/internal/protocols/mpegts/to_stream.go +++ b/internal/protocols/mpegts/to_stream.go @@ -112,8 +112,8 @@ func ToStream(r *mpegts.Reader, stream **stream.Stream) ([]*description.Media, e medi = &description.Media{ Type: description.MediaTypeAudio, Formats: []format.Format{&format.Opus{ - PayloadTyp: 96, - IsStereo: (codec.ChannelCount >= 2), + PayloadTyp: 96, + ChannelCount: codec.ChannelCount, }}, } diff --git a/internal/protocols/webrtc/incoming_track.go b/internal/protocols/webrtc/incoming_track.go index 7f11868f2d7..6a8415119aa 100644 --- a/internal/protocols/webrtc/incoming_track.go +++ b/internal/protocols/webrtc/incoming_track.go @@ -72,7 +72,12 @@ func newIncomingTrack( case strings.ToLower(webrtc.MimeTypeOpus): t.format = &format.Opus{ PayloadTyp: uint8(track.PayloadType()), - IsStereo: strings.Contains(track.Codec().SDPFmtpLine, "stereo=1"), + ChannelCount: func() int { + if strings.Contains(track.Codec().SDPFmtpLine, "stereo=1") { + return 2 + } + return 1 + }(), } case strings.ToLower(webrtc.MimeTypeG722): diff --git a/internal/record/format_fmp4.go b/internal/record/format_fmp4.go index b8165a0ab21..a8a0f8cbff3 100644 --- a/internal/record/format_fmp4.go +++ b/internal/record/format_fmp4.go @@ -594,12 +594,7 @@ func (f *formatFMP4) initialize() { case *rtspformat.Opus: codec := &fmp4.CodecOpus{ - ChannelCount: func() int { - if forma.IsStereo { - return 2 - } - return 1 - }(), + ChannelCount: forma.ChannelCount, } track := addTrack(forma, codec) diff --git a/internal/record/format_mpegts.go b/internal/record/format_mpegts.go index a541a06ed0a..60f778cf616 100644 --- a/internal/record/format_mpegts.go +++ b/internal/record/format_mpegts.go @@ -184,12 +184,7 @@ func (f *formatMPEGTS) initialize() { case *rtspformat.Opus: track := addTrack(forma, &mpegts.CodecOpus{ - ChannelCount: func() int { - if forma.IsStereo { - return 2 - } - return 1 - }(), + ChannelCount: forma.ChannelCount, }) f.a.agent.Stream.AddReader(f.a.writer, media, forma, func(u unit.Unit) error { diff --git a/internal/servers/hls/muxer_instance.go b/internal/servers/hls/muxer_instance.go index 1c512e5f003..a229076048d 100644 --- a/internal/servers/hls/muxer_instance.go +++ b/internal/servers/hls/muxer_instance.go @@ -227,12 +227,7 @@ func (mi *muxerInstance) createAudioTrack() *gohlslib.Track { return &gohlslib.Track{ Codec: &codecs.Opus{ - ChannelCount: func() int { - if audioFormatOpus.IsStereo { - return 2 - } - return 1 - }(), + ChannelCount: audioFormatOpus.ChannelCount, }, } } diff --git a/internal/servers/webrtc/session.go b/internal/servers/webrtc/session.go index cf6cc42ee64..3b40aaaffac 100644 --- a/internal/servers/webrtc/session.go +++ b/internal/servers/webrtc/session.go @@ -215,6 +215,10 @@ func findAudioTrack( if opusFormat != nil { return opusFormat, func(track *webrtc.OutgoingTrack) error { + if opusFormat.ChannelCount > 2 { + return fmt.Errorf("unsupported Opus channel count: %d", opusFormat.ChannelCount) + } + stream.AddReader(writer, media, opusFormat, func(u unit.Unit) error { for _, pkt := range u.GetRTPPackets() { track.WriteRTP(pkt) //nolint:errcheck diff --git a/internal/staticsources/hls/source.go b/internal/staticsources/hls/source.go index bbffce65187..4e81d42f940 100644 --- a/internal/staticsources/hls/source.go +++ b/internal/staticsources/hls/source.go @@ -180,8 +180,8 @@ func (s *Source) Run(params defs.StaticSourceRunParams) error { medi = &description.Media{ Type: description.MediaTypeAudio, Formats: []format.Format{&format.Opus{ - PayloadTyp: 96, - IsStereo: (tcodec.ChannelCount >= 2), + PayloadTyp: 96, + ChannelCount: tcodec.ChannelCount, }}, } diff --git a/internal/staticsources/webrtc/source_test.go b/internal/staticsources/webrtc/source_test.go index 7e061707418..612cc8595ab 100644 --- a/internal/staticsources/webrtc/source_test.go +++ b/internal/staticsources/webrtc/source_test.go @@ -45,8 +45,8 @@ func TestSource(t *testing.T) { tracks, err := pc.SetupOutgoingTracks( nil, &format.Opus{ - PayloadTyp: 111, - IsStereo: true, + PayloadTyp: 111, + ChannelCount: 2, }, ) require.NoError(t, err)