diff --git a/src/utils/webrtc/simplewebrtc/peer.js b/src/utils/webrtc/simplewebrtc/peer.js index 2f592176c44..a4e397242d9 100644 --- a/src/utils/webrtc/simplewebrtc/peer.js +++ b/src/utils/webrtc/simplewebrtc/peer.js @@ -356,6 +356,22 @@ function mungeSdpForSimulcasting(sdp) { } /* eslint-enable */ +/** + * Raises the "max-fs" (maximum frame size in macroblocks - 16x16 px) + * codec parameter in an SDP so high-resolution screens are not downscaled. + * Firefox defaults the VP8/VP9 "max-fs" to ~QHD (2560×1440px): + * - a=fmtp:120 max-fs=12288;max-fr=60 + * Raising it lets Firefox encode up to ~4K (3840×2160px): + * - a=fmtp:120 max-fs=36864;max-fr=60 + * Other browsers are not noticed to be affected with that limitation. + * + * @param {string} sdp the SDP string to munge + * @return {string} the updated SDP string + */ +function mungeSdpForScreenMaxFs(sdp) { + return sdp.replace(/max-fs=\d+/g, 'max-fs=' + 36864) +} + Peer.prototype.offer = function(options) { const sendVideo = this.sendVideoIfAvailable && this.type !== 'screen' if (sendVideo && this.enableSimulcast && adapter.browserDetails.browser === 'firefox') { @@ -401,6 +417,12 @@ Peer.prototype.offer = function(options) { } } + // SDP munging only needed for Firefox screensharing (for 4K screens) + if (this.type === 'screen' && adapter.browserDetails.browser === 'firefox') { + console.debug('Raising VP8/9 max-fs for Firefox screensharing') + offer.sdp = mungeSdpForScreenMaxFs(offer.sdp) + } + this.pc.setLocalDescription(offer).then(function() { if (this.parent.config.nick) { // The offer is a RTCSessionDescription that only serializes