Skip to content

Commit

Permalink
fix(RTC): Fix capture resolution for Safari desktop tracks.
Browse files Browse the repository at this point in the history
The browser returns height as 0 at track creation time. Fixes an issue where Safari's screenshare shows as black.
  • Loading branch information
jallamsetty1 committed Feb 13, 2024
1 parent 95f7e7b commit c749528
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
13 changes: 13 additions & 0 deletions modules/RTC/JitsiLocalTrack.js
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,19 @@ export default class JitsiLocalTrack extends JitsiTrack {
return undefined;
}

/**
* Returns the capture resolution of the video track.
*
* @returns {Number}
*/
getCaptureResolution() {
if (this.videoType === VideoType.CAMERA || !browser.isWebKitBased()) {
return this.resolution;
}

return this.getHeight();
}

/**
* Returns device id associated with track.
*
Expand Down
8 changes: 8 additions & 0 deletions modules/RTC/MockClasses.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,14 @@ export class MockJitsiLocalTrack {
return this.track.height;
}

/**
* Returns the capture resolution.
* @returns {number}
*/
getCaptureResolution() {
return this.getHeight();
}

/**
* Returns track.
* @returns {MockTrack}
Expand Down
8 changes: 4 additions & 4 deletions modules/RTC/TPCUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class TPCUtils {
*/
_calculateActiveEncodingParams(localVideoTrack, codec, newHeight) {
const codecBitrates = this.codecSettings[codec].maxBitratesVideo;
const trackCaptureHeight = localVideoTrack.resolution;
const trackCaptureHeight = localVideoTrack.getCaptureResolution();
const effectiveNewHeight = newHeight > trackCaptureHeight ? trackCaptureHeight : newHeight;
const desktopShareBitrate = this.pc.options?.videoQuality?.desktopbitrate || codecBitrates.ssHigh;
const isScreenshare = localVideoTrack.getVideoType() === VideoType.DESKTOP;
Expand Down Expand Up @@ -177,7 +177,7 @@ export class TPCUtils {
* @param {String} codec
*/
_getVideoStreamEncodings(localTrack, codec) {
const captureResolution = localTrack.resolution;
const captureResolution = localTrack.getCaptureResolution();
const codecBitrates = this.codecSettings[codec].maxBitratesVideo;
const videoType = localTrack.getVideoType();
let effectiveScaleFactors = SIM_LAYERS.map(sim => sim.scaleFactor);
Expand Down Expand Up @@ -360,7 +360,7 @@ export class TPCUtils {
* @returns {Array<boolean>}
*/
calculateEncodingsActiveState(localVideoTrack, codec, newHeight) {
const height = localVideoTrack.resolution;
const height = localVideoTrack.getCaptureResolution();
const videoStreamEncodings = this._getVideoStreamEncodings(localVideoTrack, codec);
const encodingsState = videoStreamEncodings
.map(encoding => height / encoding.scaleResolutionDownBy)
Expand Down Expand Up @@ -543,7 +543,7 @@ export class TPCUtils {
* @returns {number|null} The max encoded resolution for the given video track.
*/
getConfiguredEncodeResolution(localVideoTrack, codec) {
const height = localVideoTrack.resolution;
const height = localVideoTrack.getCaptureResolution();
const videoSender = this.pc.findSenderForTrack(localVideoTrack.getTrack());
let maxHeight = 0;

Expand Down
4 changes: 2 additions & 2 deletions modules/RTC/TraceablePeerConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -2062,7 +2062,7 @@ TraceablePeerConnection.prototype._setMaxBitrates = function(description, isLoca
if (localTrack.getVideoType() === VideoType.DESKTOP) {
maxBitrate = codecScalabilityModeSettings.maxBitratesVideo.ssHigh;
} else {
const { level } = VIDEO_QUALITY_LEVELS.find(lvl => lvl.height <= localTrack.resolution);
const { level } = VIDEO_QUALITY_LEVELS.find(lvl => lvl.height <= localTrack.getCaptureResolution());

maxBitrate = codecScalabilityModeSettings.maxBitratesVideo[level];
}
Expand Down Expand Up @@ -2240,7 +2240,7 @@ TraceablePeerConnection.prototype.setSenderVideoConstraints = function(frameHeig
if ((localVideoTrack.getVideoType() === VideoType.CAMERA && configuredResolution === frameHeight)
|| (localVideoTrack.getVideoType() === VideoType.DESKTOP
&& frameHeight > 0
&& configuredResolution === localVideoTrack.resolution)) {
&& configuredResolution === localVideoTrack.getCaptureResolution())) {
return Promise.resolve();
}

Expand Down

0 comments on commit c749528

Please sign in to comment.