ref(presenter): refactor the desktop resize logic for presenter.

This commit is contained in:
Jaya Allamsetty 2020-11-09 10:03:27 -05:00 committed by Jaya Allamsetty
parent 68d97f6d9d
commit 1e07385ac0
1 changed files with 22 additions and 23 deletions

View File

@ -1651,39 +1651,37 @@ export default {
// Create a new presenter track and apply the presenter effect. // Create a new presenter track and apply the presenter effect.
if (!this.localPresenterVideo && !mute) { if (!this.localPresenterVideo && !mute) {
const { height, width } = this.localVideo.track.getSettings() ?? this.localVideo.track.getConstraints(); const { height, width } = this.localVideo.track.getSettings() ?? this.localVideo.track.getConstraints();
let desktopResizeConstraints = {}; const isPortrait = height >= width;
let resizeDesktopStream = false;
const DESKTOP_STREAM_CAP = 720; const DESKTOP_STREAM_CAP = 720;
// Resizing the desktop track for presenter is causing blurriness of the desktop share. // Config.js setting for resizing high resolution desktop tracks to 720p when presenter is turned on.
// Disable this behavior for now until it is fixed in Chrome. The stream needs to be resized const resizeEnabled = config.videoQuality && config.videoQuality.resizeDesktopForPresenter;
// Firefox always. const highResolutionTrack
if ((config.videoQuality && config.videoQuality.resizeDesktopForPresenter) || browser.isFirefox()) { = (isPortrait && width > DESKTOP_STREAM_CAP) || (!isPortrait && height > DESKTOP_STREAM_CAP);
// Resizing is needed when the window is bigger than 720p.
// Resizing the desktop track for presenter is causing blurriness of the desktop share on chrome.
// Disable resizing by default, enable it only when config.js setting is enabled.
// Firefox doesn't return width and height for desktop tracks. Therefore, track needs to be resized
// for creating the canvas for presenter.
const resizeDesktopStream = browser.isFirefox() || (highResolutionTrack && resizeEnabled);
if (resizeDesktopStream) {
let desktopResizeConstraints = {};
if (height && width) { if (height && width) {
const advancedConstraints = [ { aspectRatio: (width / height).toPrecision(4) } ]; const advancedConstraints = [ { aspectRatio: (width / height).toPrecision(4) } ];
const isPortrait = height >= width; const constraint = isPortrait ? { width: DESKTOP_STREAM_CAP } : { height: DESKTOP_STREAM_CAP };
// Determine which dimension needs resizing and resize only that side advancedConstraints.push(constraint);
// keeping the aspect ratio same as before.
if (isPortrait && width > DESKTOP_STREAM_CAP) {
resizeDesktopStream = true;
advancedConstraints.push({ width: DESKTOP_STREAM_CAP });
} else if (!isPortrait && height > DESKTOP_STREAM_CAP) {
resizeDesktopStream = true;
advancedConstraints.push({ height: DESKTOP_STREAM_CAP });
}
desktopResizeConstraints.advanced = advancedConstraints; desktopResizeConstraints.advanced = advancedConstraints;
} else { } else {
resizeDesktopStream = true;
desktopResizeConstraints = { desktopResizeConstraints = {
width: 1280, width: 1280,
height: 720 height: 720
}; };
} }
}
if (resizeDesktopStream) { // Apply the contraints on the desktop track.
try { try {
await this.localVideo.track.applyConstraints(desktopResizeConstraints); await this.localVideo.track.applyConstraints(desktopResizeConstraints);
} catch (err) { } catch (err) {
@ -1695,17 +1693,18 @@ export default {
const trackHeight = resizeDesktopStream const trackHeight = resizeDesktopStream
? this.localVideo.track.getSettings().height ?? DESKTOP_STREAM_CAP ? this.localVideo.track.getSettings().height ?? DESKTOP_STREAM_CAP
: height; : height;
const defaultCamera = getUserSelectedCameraDeviceId(APP.store.getState());
let effect; let effect;
try { try {
effect = await this._createPresenterStreamEffect(trackHeight, defaultCamera); effect = await this._createPresenterStreamEffect(trackHeight);
} catch (err) { } catch (err) {
logger.error('Failed to unmute Presenter Video'); logger.error('Failed to unmute Presenter Video', err);
maybeShowErrorDialog(err); maybeShowErrorDialog(err);
return; return;
} }
// Replace the desktop track on the peerconnection.
try { try {
await this.localVideo.setEffect(effect); await this.localVideo.setEffect(effect);
APP.store.dispatch(setVideoMuted(mute, MEDIA_TYPE.PRESENTER)); APP.store.dispatch(setVideoMuted(mute, MEDIA_TYPE.PRESENTER));