From 7d484a8d73eb19b797c0b3113bae81131746e0d3 Mon Sep 17 00:00:00 2001 From: Jaya Allamsetty Date: Thu, 13 Feb 2025 17:52:13 -0500 Subject: [PATCH] fix(codec) Fix AV1/VP9 support on Firefox. Firefox added support for AV1 with DD and VP9 SVC is also working as expected in Firefox 136. --- modules/RTC/TPCUtils.js | 4 +++- modules/RTC/TraceablePeerConnection.js | 14 +++++++------- modules/browser/BrowserCapabilities.js | 13 +++++++------ modules/qualitycontrol/CodecSelection.js | 5 ++--- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/modules/RTC/TPCUtils.js b/modules/RTC/TPCUtils.js index 98537d677e..c8e24aee5e 100644 --- a/modules/RTC/TPCUtils.js +++ b/modules/RTC/TPCUtils.js @@ -222,7 +222,9 @@ export class TPCUtils { // https://hg.mozilla.org/mozilla-central/rev/b0348f1f8d7197fb87158ba74542d28d46133997 // This revert seems to be applied only to camera tracks, the desktop stream encodings still have the // resolution order of 4:2:1. - if (browser.isFirefox() && (videoType === VideoType.DESKTOP || browser.isVersionLessThan(117))) { + if (browser.isFirefox() + && !browser.supportsScalabilityModeAPI() + && (videoType === VideoType.DESKTOP || browser.isVersionLessThan(117))) { effectiveBitrates = effectiveBitrates.reverse(); effectiveScaleFactors = effectiveScaleFactors.reverse(); } diff --git a/modules/RTC/TraceablePeerConnection.js b/modules/RTC/TraceablePeerConnection.js index 71f0d582b2..87bd17e559 100644 --- a/modules/RTC/TraceablePeerConnection.js +++ b/modules/RTC/TraceablePeerConnection.js @@ -1332,7 +1332,7 @@ TraceablePeerConnection.prototype.addTrack = async function(track, isInitiator = } // On Firefox, the encodings have to be configured on the sender only after the transceiver is created. - if (browser.isFirefox() && webrtcStream) { + if (browser.isFirefox() && webrtcStream && this.doesTrueSimulcast(track)) { await this._setEncodings(track); } }; @@ -1644,17 +1644,17 @@ TraceablePeerConnection.prototype.replaceTrack = function(oldTrack, newTrack, is // https://bugzilla.mozilla.org/show_bug.cgi?id=1768729 the video stream won't be rendered. // That's why we need keep the direction to SENDRECV for FF. // - // NOTE: If we return back to the approach of not removing the track for FF and instead using the - // enabled property for mute or stopping screensharing we may need to change the direction to + // NOTE: If we return to the approach of not removing the track for FF and instead using the + // enabled property for muting the track, we may need to change the direction to // RECVONLY if FF still sends the media even though the enabled flag is set to false. transceiver.direction = newTrack || browser.isFirefox() ? MediaDirection.SENDRECV : MediaDirection.RECVONLY; - // Avoid re-configuring the encodings on Chromium/Safari, this is needed only on Firefox. + // Configure simulcast encodings on Firefox when a track is added to the peerconnection for the first time. const configureEncodingsPromise - = !newTrack || browser.usesSdpMungingForSimulcast() - ? Promise.resolve() - : this._setEncodings(newTrack); + = browser.isFirefox() && !oldTrack && newTrack && this.doesTrueSimulcast(newTrack) + ? this._setEncodings(newTrack) + : Promise.resolve(); return configureEncodingsPromise.then(() => this.isP2P); }); diff --git a/modules/browser/BrowserCapabilities.js b/modules/browser/BrowserCapabilities.js index 24970d7b51..71a751c72d 100644 --- a/modules/browser/BrowserCapabilities.js +++ b/modules/browser/BrowserCapabilities.js @@ -177,7 +177,7 @@ export default class BrowserCapabilities extends BrowserDetection { * @returns {boolean} */ supportsDDExtHeaders() { - return !this.isFirefox(); + return !(this.isFirefox() && this.isVersionLessThan('136')); } /** @@ -233,7 +233,8 @@ export default class BrowserCapabilities extends BrowserDetection { * @returns {boolean} */ supportsScalabilityModeAPI() { - return this.isChromiumBased() && this.isEngineVersionGreaterThan(112); + return (this.isChromiumBased() && this.isEngineVersionGreaterThan(112)) + || (this.isFirefox() && this.isVersionGreaterThan(135)); } /** @@ -246,12 +247,12 @@ export default class BrowserCapabilities extends BrowserDetection { } /** - * Returns true if VP9 is supported by the client on the browser. VP9 is currently disabled on Firefox and Safari - * because of issues with rendering. Please check https://bugzilla.mozilla.org/show_bug.cgi?id=1492500, - * https://bugs.webkit.org/show_bug.cgi?id=231071 and https://bugs.webkit.org/show_bug.cgi?id=231074 for details. + * Returns true if VP9 is supported by the client on the browser. VP9 is currently disabled on Safari + * and older versions of Firefox because of issues. Please check https://bugs.webkit.org/show_bug.cgi?id=231074 for + * details. */ supportsVP9() { - return this.isChromiumBased() || this.isReactNative(); + return !(this.isWebKitBased() || (this.isFirefox() && this.isVersionLessThan('136'))); } /** diff --git a/modules/qualitycontrol/CodecSelection.js b/modules/qualitycontrol/CodecSelection.js index 568680c801..a0cf5ffb78 100644 --- a/modules/qualitycontrol/CodecSelection.js +++ b/modules/qualitycontrol/CodecSelection.js @@ -72,11 +72,10 @@ export class CodecSelection { } // Push VP9 to the end of the list so that the client continues to decode VP9 even if its not - // preferable to encode VP9 (because of browser bugs on the encoding side or added complexity on mobile - // devices). Currently, VP9 encode is supported on Chrome and on Safari (only for p2p). + // preferable to encode VP9 (because of browser bugs on the encoding side or other reasons). const isVp9EncodeSupported = browser.supportsVP9() || (browser.isWebKitBased() && connectionType === 'p2p'); - if (!isVp9EncodeSupported || this.conference.isE2EEEnabled()) { + if (!isVp9EncodeSupported) { const index = selectedOrder.findIndex(codec => codec === CodecMimeType.VP9); if (index !== -1) {