From c20a91d2b2252ad3ea5df2484d6becc2a2d56670 Mon Sep 17 00:00:00 2001 From: cnderrauber Date: Mon, 22 Aug 2022 17:40:12 +0800 Subject: [PATCH] enable red by default (#940) * enable red by default * fix test case --- pkg/config/config.go | 1 + pkg/rtc/clientinfo.go | 2 +- pkg/rtc/mediaengine.go | 3 ++- pkg/rtc/participant_internal_test.go | 2 ++ pkg/sfu/redprimaryreceiver.go | 4 ++++ 5 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 260f9de04..080c03418 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -235,6 +235,7 @@ func NewConfig(confString string, c *cli.Context) (*Config, error) { AutoCreate: true, EnabledCodecs: []CodecSpec{ {Mime: webrtc.MimeTypeOpus}, + {Mime: "audio/red"}, {Mime: webrtc.MimeTypeVP8}, {Mime: webrtc.MimeTypeH264}, // {Mime: webrtc.MimeTypeAV1}, diff --git a/pkg/rtc/clientinfo.go b/pkg/rtc/clientinfo.go index e9e10f0dc..ab8598063 100644 --- a/pkg/rtc/clientinfo.go +++ b/pkg/rtc/clientinfo.go @@ -7,5 +7,5 @@ type ClientInfo struct { } func (c ClientInfo) SupportsAudioRED() bool { - return c.ClientInfo.Browser != "firefox" && c.ClientInfo.Browser != "safari" + return c.ClientInfo != nil && c.ClientInfo.Browser != "firefox" && c.ClientInfo.Browser != "safari" } diff --git a/pkg/rtc/mediaengine.go b/pkg/rtc/mediaengine.go index b4ead8d12..aa2a8e70c 100644 --- a/pkg/rtc/mediaengine.go +++ b/pkg/rtc/mediaengine.go @@ -6,6 +6,7 @@ import ( "github.com/pion/webrtc/v3" + "github.com/livekit/livekit-server/pkg/sfu" "github.com/livekit/protocol/livekit" ) @@ -24,7 +25,7 @@ func registerCodecs(me *webrtc.MediaEngine, codecs []*livekit.Codec, rtcpFeedbac return err } } - redCodec := webrtc.RTPCodecCapability{MimeType: "audio/red", ClockRate: 48000, Channels: 2} + redCodec := webrtc.RTPCodecCapability{MimeType: sfu.MimeTypeAudioRed, ClockRate: 48000, Channels: 2} if opusPayload != 0 && isCodecEnabled(codecs, redCodec) { redCodec.SDPFmtpLine = fmt.Sprintf("%d/%d", opusPayload, opusPayload) if err := me.RegisterCodec(webrtc.RTPCodecParameters{ diff --git a/pkg/rtc/participant_internal_test.go b/pkg/rtc/participant_internal_test.go index d46aad178..2ea4c68f7 100644 --- a/pkg/rtc/participant_internal_test.go +++ b/pkg/rtc/participant_internal_test.go @@ -434,6 +434,7 @@ type participantOpts struct { protocolVersion types.ProtocolVersion publisher bool clientConf *livekit.ClientConfiguration + clientInfo *livekit.ClientInfo } func newParticipantForTestWithOpts(identity livekit.ParticipantIdentity, opts *participantOpts) *ParticipantImpl { @@ -477,6 +478,7 @@ func newParticipantForTestWithOpts(identity livekit.ParticipantIdentity, opts *p Grants: grants, EnabledCodecs: enabledCodecs, ClientConf: opts.clientConf, + ClientInfo: ClientInfo{ClientInfo: opts.clientInfo}, }) p.isPublisher.Store(opts.publisher) diff --git a/pkg/sfu/redprimaryreceiver.go b/pkg/sfu/redprimaryreceiver.go index 22f265794..70caad1bb 100644 --- a/pkg/sfu/redprimaryreceiver.go +++ b/pkg/sfu/redprimaryreceiver.go @@ -84,6 +84,10 @@ func (r *RedPrimaryReceiver) DeleteDownTrack(subscriberID livekit.ParticipantID) r.downTrackSpreader.Free(subscriberID) } +func (r *RedPrimaryReceiver) CanClose() bool { + return r.closed.Load() || r.downTrackSpreader.DownTrackCount() == 0 +} + func (r *RedPrimaryReceiver) Close() { r.closed.Store(true) for _, dt := range r.downTrackSpreader.ResetAndGetDownTracks() {