瀏覽代碼

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 年之前
父節點
當前提交
623277289b
共有 3 個檔案被更改,包括 29 行新增34 行删除
  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 查看文件

@@ -334,15 +334,6 @@ export default {
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 337
                 return tracks;
347 338
             })
348 339
             .catch(error => {
@@ -531,24 +522,6 @@ export default {
531 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 525
     precallTest,
553 526
 
554 527
     /* eslint-enable max-params */

+ 29
- 5
modules/RTC/ScreenObtainer.js 查看文件

@@ -180,11 +180,15 @@ const ScreenObtainer = {
180 180
 
181 181
                         // We have to use the old API on Electron to get a desktop stream.
182 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 192
                     } else {
189 193
                         // As noted in Chrome Desktop Capture API:
190 194
                         // If user didn't select any source (i.e. canceled the prompt)
@@ -257,6 +261,7 @@ const ScreenObtainer = {
257 261
 
258 262
         getDisplayMedia(constraints)
259 263
             .then(stream => {
264
+                this.setContentHint(stream);
260 265
                 callback({
261 266
                     stream,
262 267
                     sourceId: stream.id
@@ -294,6 +299,7 @@ const ScreenObtainer = {
294 299
 
295 300
         navigator.mediaDevices.getDisplayMedia({ video: true })
296 301
             .then(stream => {
302
+                this.setContentHint(stream);
297 303
                 callback({
298 304
                     stream,
299 305
                     sourceId: stream.id });
@@ -304,6 +310,24 @@ const ScreenObtainer = {
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 332
      * Sets the max frame rate to be used for a desktop track capture.
309 333
      *

+ 0
- 2
types/hand-crafted/JitsiMeetJS.d.ts 查看文件

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

Loading…
取消
儲存