Skip to content

Commit

Permalink
fix(ScreenObtainer): Apply contentHint on captured desktop track corr…
Browse files Browse the repository at this point in the history
…ectly.

contentHint needs to be set to 'motion' for high fps SS and 'detail' otherwise. Fixes jitsi#2298.
  • Loading branch information
jallamsetty1 committed Jun 28, 2023
1 parent c912d35 commit 99776f3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 34 deletions.
27 changes: 0 additions & 27 deletions JitsiMeetJS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,15 +334,6 @@ export default {
}
}

// set the contentHint to "detail" for desktop tracks
// eslint-disable-next-line prefer-const
for (const track of tracks) {
if (track.type === MediaType.VIDEO
&& track.videoType === 'desktop') {
this.setVideoTrackContentHints(track.track, 'detail');
}
}

return tracks;
})
.catch(error => {
Expand Down Expand Up @@ -531,24 +522,6 @@ export default {
NetworkInfo.updateNetworkInfo({ isOnline });
},

/**
* Set the contentHint on the transmitted stream track to indicate
* charaterstics in the video stream, which informs PeerConnection
* on how to encode the track (to prefer motion or individual frame detail)
* @param {MediaStreamTrack} track - the track that is transmitted
* @param {String} hint - contentHint value that needs to be set on the track
*/
setVideoTrackContentHints(track, hint) {
if ('contentHint' in track) {
track.contentHint = hint;
if (track.contentHint !== hint) {
logger.debug('Invalid video track contentHint');
}
} else {
logger.debug('MediaStreamTrack contentHint attribute not supported');
}
},

precallTest,

/* eslint-enable max-params */
Expand Down
33 changes: 28 additions & 5 deletions modules/RTC/ScreenObtainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,14 @@ const ScreenObtainer = {

// We have to use the old API on Electron to get a desktop stream.
navigator.mediaDevices.getUserMedia(constraints)
.then(stream => onSuccess({
stream,
sourceId: streamId,
sourceType: streamType
}), onFailure);
.then(stream => () => {
this.setContentHint(stream);
onSuccess({
stream,
sourceId: streamId,
sourceType: streamType
});
}, onFailure);
} else {
// As noted in Chrome Desktop Capture API:
// If user didn't select any source (i.e. canceled the prompt)
Expand Down Expand Up @@ -257,6 +260,7 @@ const ScreenObtainer = {

getDisplayMedia(constraints)
.then(stream => {
this.setContentHint(stream);
callback({
stream,
sourceId: stream.id
Expand Down Expand Up @@ -294,6 +298,7 @@ const ScreenObtainer = {

navigator.mediaDevices.getDisplayMedia({ video: true })
.then(stream => {
this.setContentHint(stream);
callback({
stream,
sourceId: stream.id });
Expand All @@ -304,6 +309,24 @@ const ScreenObtainer = {
});
},

/** Sets the contentHint on the transmitted MediaStreamTrack to indicate charaterstics in the video stream, which
* informs RTCPeerConnection on how to encode the track (to prefer motion or individual frame detail).
*
* @param {MediaStream} stream - The captured desktop stream.
* @returns {void}
*/
setContentHint(stream) {
const { desktopSharingFrameRate } = this.options;
const desktopTrack = stream.getVideoTracks()[0];

// Set contentHint on the desktop track based on the fps requested.
if ('contentHint' in desktopTrack) {
desktopTrack.contentHint = desktopSharingFrameRate?.max > SS_DEFAULT_FRAME_RATE ? 'motion' : 'detail';
} else {
logger.warn('MediaStreamTrack contentHint attribute not supported');
}
},

/**
* Sets the max frame rate to be used for a desktop track capture.
*
Expand Down
2 changes: 0 additions & 2 deletions types/hand-crafted/JitsiMeetJS.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ export type JitsiMeetJSType = {

setNetworkInfo: ( { isOnline: boolean } ) => void;

setVideoTrackContentHints: ( track: MediaStreamTrack, hint: string ) => void;

precallTest: PrecallTest;

util: {
Expand Down

0 comments on commit 99776f3

Please sign in to comment.