Browse Source

fix(ScreenObtainer): Apply contentHint on captured desktop track correctly.

contentHint needs to be set to 'motion' for high fps SS and 'detail' otherwise. Fixes https://github.com/jitsi/lib-jitsi-meet/issues/2298.
release-8443
Jaya Allamsetty 2 years ago
parent
commit
623277289b
3 changed files with 29 additions and 34 deletions
  1. 0
    27
      JitsiMeetJS.ts
  2. 29
    5
      modules/RTC/ScreenObtainer.js
  3. 0
    2
      types/hand-crafted/JitsiMeetJS.d.ts

+ 0
- 27
JitsiMeetJS.ts View File

334
                     }
334
                     }
335
                 }
335
                 }
336
 
336
 
337
-                // set the contentHint to "detail" for desktop tracks
338
-                // eslint-disable-next-line prefer-const
339
-                for (const track of tracks) {
340
-                    if (track.type === MediaType.VIDEO
341
-                        && track.videoType === 'desktop') {
342
-                        this.setVideoTrackContentHints(track.track, 'detail');
343
-                    }
344
-                }
345
-
346
                 return tracks;
337
                 return tracks;
347
             })
338
             })
348
             .catch(error => {
339
             .catch(error => {
531
         NetworkInfo.updateNetworkInfo({ isOnline });
522
         NetworkInfo.updateNetworkInfo({ isOnline });
532
     },
523
     },
533
 
524
 
534
-    /**
535
-     * Set the contentHint on the transmitted stream track to indicate
536
-     * charaterstics in the video stream, which informs PeerConnection
537
-     * on how to encode the track (to prefer motion or individual frame detail)
538
-     * @param {MediaStreamTrack} track - the track that is transmitted
539
-     * @param {String} hint - contentHint value that needs to be set on the track
540
-     */
541
-    setVideoTrackContentHints(track, hint) {
542
-        if ('contentHint' in track) {
543
-            track.contentHint = hint;
544
-            if (track.contentHint !== hint) {
545
-                logger.debug('Invalid video track contentHint');
546
-            }
547
-        } else {
548
-            logger.debug('MediaStreamTrack contentHint attribute not supported');
549
-        }
550
-    },
551
-
552
     precallTest,
525
     precallTest,
553
 
526
 
554
     /* eslint-enable max-params */
527
     /* eslint-enable max-params */

+ 29
- 5
modules/RTC/ScreenObtainer.js View File

180
 
180
 
181
                         // We have to use the old API on Electron to get a desktop stream.
181
                         // We have to use the old API on Electron to get a desktop stream.
182
                         navigator.mediaDevices.getUserMedia(constraints)
182
                         navigator.mediaDevices.getUserMedia(constraints)
183
-                            .then(stream => onSuccess({
184
-                                stream,
185
-                                sourceId: streamId,
186
-                                sourceType: streamType
187
-                            }), onFailure);
183
+                            .then(stream => {
184
+                                this.setContentHint(stream);
185
+                                onSuccess({
186
+                                    stream,
187
+                                    sourceId: streamId,
188
+                                    sourceType: streamType
189
+                                });
190
+                            })
191
+                            .catch(err => onFailure(err));
188
                     } else {
192
                     } else {
189
                         // As noted in Chrome Desktop Capture API:
193
                         // As noted in Chrome Desktop Capture API:
190
                         // If user didn't select any source (i.e. canceled the prompt)
194
                         // If user didn't select any source (i.e. canceled the prompt)
257
 
261
 
258
         getDisplayMedia(constraints)
262
         getDisplayMedia(constraints)
259
             .then(stream => {
263
             .then(stream => {
264
+                this.setContentHint(stream);
260
                 callback({
265
                 callback({
261
                     stream,
266
                     stream,
262
                     sourceId: stream.id
267
                     sourceId: stream.id
294
 
299
 
295
         navigator.mediaDevices.getDisplayMedia({ video: true })
300
         navigator.mediaDevices.getDisplayMedia({ video: true })
296
             .then(stream => {
301
             .then(stream => {
302
+                this.setContentHint(stream);
297
                 callback({
303
                 callback({
298
                     stream,
304
                     stream,
299
                     sourceId: stream.id });
305
                     sourceId: stream.id });
304
             });
310
             });
305
     },
311
     },
306
 
312
 
313
+    /** Sets the contentHint on the transmitted MediaStreamTrack to indicate charaterstics in the video stream, which
314
+     * informs RTCPeerConnection on how to encode the track (to prefer motion or individual frame detail).
315
+     *
316
+     * @param {MediaStream} stream - The captured desktop stream.
317
+     * @returns {void}
318
+     */
319
+    setContentHint(stream) {
320
+        const { desktopSharingFrameRate } = this.options;
321
+        const desktopTrack = stream.getVideoTracks()[0];
322
+
323
+        // Set contentHint on the desktop track based on the fps requested.
324
+        if ('contentHint' in desktopTrack) {
325
+            desktopTrack.contentHint = desktopSharingFrameRate?.max > SS_DEFAULT_FRAME_RATE ? 'motion' : 'detail';
326
+        } else {
327
+            logger.warn('MediaStreamTrack contentHint attribute not supported');
328
+        }
329
+    },
330
+
307
     /**
331
     /**
308
      * Sets the max frame rate to be used for a desktop track capture.
332
      * Sets the max frame rate to be used for a desktop track capture.
309
      *
333
      *

+ 0
- 2
types/hand-crafted/JitsiMeetJS.d.ts View File

137
 
137
 
138
   setNetworkInfo: ( { isOnline: boolean } ) => void;
138
   setNetworkInfo: ( { isOnline: boolean } ) => void;
139
 
139
 
140
-  setVideoTrackContentHints: ( track: MediaStreamTrack, hint: string ) => void;
141
-
142
   precallTest: PrecallTest;
140
   precallTest: PrecallTest;
143
 
141
 
144
   util: {
142
   util: {

Loading…
Cancel
Save