From 0296a5bd8672453dcea01e30582ae2bd8238754b Mon Sep 17 00:00:00 2001 From: cnderrauber Date: Wed, 25 Oct 2023 16:59:37 +0800 Subject: [PATCH] Remove un-preferred codecs for android firefox (#2183) * Remove un-preferred codecs for android firefox Android firefox don't comply with the codec order in answer sdp and has problem to publish h.264, remove other codecs to fix this. * false(false) is true --- pkg/rtc/clientinfo.go | 8 ++++++++ pkg/rtc/participant_sdp.go | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/pkg/rtc/clientinfo.go b/pkg/rtc/clientinfo.go index 7912968b0..62117e0d1 100644 --- a/pkg/rtc/clientinfo.go +++ b/pkg/rtc/clientinfo.go @@ -37,6 +37,10 @@ func (c ClientInfo) isGo() bool { return c.ClientInfo != nil && c.ClientInfo.Sdk == livekit.ClientInfo_GO } +func (c ClientInfo) isLinux() bool { + return c.ClientInfo != nil && strings.EqualFold(c.ClientInfo.Os, "linux") +} + func (c ClientInfo) SupportsAudioRED() bool { return !c.isFirefox() && !c.isSafari() } @@ -80,6 +84,10 @@ func (c ClientInfo) SupportsChangeRTPSenderEncodingActive() bool { return !c.isFirefox() } +func (c ClientInfo) ComplyWithCodecOrderInSDPAnswer() bool { + return !(c.isLinux() && c.isFirefox()) +} + // compareVersion compares a semver against the current client SDK version // returning 1 if current version is greater than version // 0 if they are the same, and -1 if it's an earlier version diff --git a/pkg/rtc/participant_sdp.go b/pkg/rtc/participant_sdp.go index 9bacce907..70829a34c 100644 --- a/pkg/rtc/participant_sdp.go +++ b/pkg/rtc/participant_sdp.go @@ -180,7 +180,10 @@ func (p *ParticipantImpl) setCodecPreferencesVideoForPublisher(offer webrtc.Sess } unmatchVideo.MediaName.Formats = append(unmatchVideo.MediaName.Formats[:0], preferredCodecs...) - unmatchVideo.MediaName.Formats = append(unmatchVideo.MediaName.Formats, leftCodecs...) + // if the client don't comply with codec order in SDP answer, only keep preferred codecs to force client to use it + if p.params.ClientInfo.ComplyWithCodecOrderInSDPAnswer() { + unmatchVideo.MediaName.Formats = append(unmatchVideo.MediaName.Formats, leftCodecs...) + } } }