Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support routing multichannel Opus between RTSP, SRT, HLS, UDP and recording in MPEG-TS and fMP4 (#3355) #3368

Merged
merged 1 commit into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
7 changes: 1 addition & 6 deletions internal/protocols/mpegts/from_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,7 @@

case *format.Opus:
track := addTrack(&mcmpegts.CodecOpus{
ChannelCount: func() int {
if forma.IsStereo {
return 2
}
return 1
}(),
ChannelCount: forma.ChannelCount,

Check warning on line 168 in internal/protocols/mpegts/from_stream.go

View check run for this annotation

Codecov / codecov/patch

internal/protocols/mpegts/from_stream.go#L168

Added line #L168 was not covered by tests
})

stream.AddReader(writer, medi, forma, func(u unit.Unit) error {
Expand Down
4 changes: 2 additions & 2 deletions internal/protocols/mpegts/to_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@
medi = &description.Media{
Type: description.MediaTypeAudio,
Formats: []format.Format{&format.Opus{
PayloadTyp: 96,
IsStereo: (codec.ChannelCount >= 2),
PayloadTyp: 96,
ChannelCount: codec.ChannelCount,

Check warning on line 116 in internal/protocols/mpegts/to_stream.go

View check run for this annotation

Codecov / codecov/patch

internal/protocols/mpegts/to_stream.go#L115-L116

Added lines #L115 - L116 were not covered by tests
}},
}

Expand Down
7 changes: 6 additions & 1 deletion internal/protocols/webrtc/incoming_track.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@
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

Check warning on line 79 in internal/protocols/webrtc/incoming_track.go

View check run for this annotation

Codecov / codecov/patch

internal/protocols/webrtc/incoming_track.go#L75-L79

Added lines #L75 - L79 were not covered by tests
}(),
}

case strings.ToLower(webrtc.MimeTypeG722):
Expand Down
7 changes: 1 addition & 6 deletions internal/record/format_fmp4.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,12 +594,7 @@

case *rtspformat.Opus:
codec := &fmp4.CodecOpus{
ChannelCount: func() int {
if forma.IsStereo {
return 2
}
return 1
}(),
ChannelCount: forma.ChannelCount,

Check warning on line 597 in internal/record/format_fmp4.go

View check run for this annotation

Codecov / codecov/patch

internal/record/format_fmp4.go#L597

Added line #L597 was not covered by tests
}
track := addTrack(forma, codec)

Expand Down
7 changes: 1 addition & 6 deletions internal/record/format_mpegts.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,7 @@

case *rtspformat.Opus:
track := addTrack(forma, &mpegts.CodecOpus{
ChannelCount: func() int {
if forma.IsStereo {
return 2
}
return 1
}(),
ChannelCount: forma.ChannelCount,

Check warning on line 187 in internal/record/format_mpegts.go

View check run for this annotation

Codecov / codecov/patch

internal/record/format_mpegts.go#L187

Added line #L187 was not covered by tests
})

f.a.agent.Stream.AddReader(f.a.writer, media, forma, func(u unit.Unit) error {
Expand Down
7 changes: 1 addition & 6 deletions internal/servers/hls/muxer_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,7 @@

return &gohlslib.Track{
Codec: &codecs.Opus{
ChannelCount: func() int {
if audioFormatOpus.IsStereo {
return 2
}
return 1
}(),
ChannelCount: audioFormatOpus.ChannelCount,

Check warning on line 230 in internal/servers/hls/muxer_instance.go

View check run for this annotation

Codecov / codecov/patch

internal/servers/hls/muxer_instance.go#L230

Added line #L230 was not covered by tests
},
}
}
Expand Down
4 changes: 4 additions & 0 deletions internal/servers/webrtc/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@

if opusFormat != nil {
return opusFormat, func(track *webrtc.OutgoingTrack) error {
if opusFormat.ChannelCount > 2 {
return fmt.Errorf("unsupported Opus channel count: %d", opusFormat.ChannelCount)
}

Check warning on line 220 in internal/servers/webrtc/session.go

View check run for this annotation

Codecov / codecov/patch

internal/servers/webrtc/session.go#L218-L220

Added lines #L218 - L220 were not covered by tests

stream.AddReader(writer, media, opusFormat, func(u unit.Unit) error {
for _, pkt := range u.GetRTPPackets() {
track.WriteRTP(pkt) //nolint:errcheck
Expand Down
4 changes: 2 additions & 2 deletions internal/staticsources/hls/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@
medi = &description.Media{
Type: description.MediaTypeAudio,
Formats: []format.Format{&format.Opus{
PayloadTyp: 96,
IsStereo: (tcodec.ChannelCount >= 2),
PayloadTyp: 96,
ChannelCount: tcodec.ChannelCount,

Check warning on line 184 in internal/staticsources/hls/source.go

View check run for this annotation

Codecov / codecov/patch

internal/staticsources/hls/source.go#L183-L184

Added lines #L183 - L184 were not covered by tests
}},
}

Expand Down
4 changes: 2 additions & 2 deletions internal/staticsources/webrtc/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading