Skip to content

Commit

Permalink
fix(codec) Fix AV1/VP9 support on Firefox.
Browse files Browse the repository at this point in the history
Firefox added support for AV1 with DD and VP9 SVC is also working as expected in Firefox 136.
  • Loading branch information
jallamsetty1 committed Feb 19, 2025
1 parent 522577a commit 7d484a8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
4 changes: 3 additions & 1 deletion modules/RTC/TPCUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
14 changes: 7 additions & 7 deletions modules/RTC/TraceablePeerConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
Expand Down Expand Up @@ -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);
});
Expand Down
13 changes: 7 additions & 6 deletions modules/browser/BrowserCapabilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export default class BrowserCapabilities extends BrowserDetection {
* @returns {boolean}
*/
supportsDDExtHeaders() {
return !this.isFirefox();
return !(this.isFirefox() && this.isVersionLessThan('136'));
}

/**
Expand Down Expand Up @@ -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));
}

/**
Expand All @@ -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')));
}

/**
Expand Down
5 changes: 2 additions & 3 deletions modules/qualitycontrol/CodecSelection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 7d484a8

Please sign in to comment.