Преглед изворни кода

fix: high CPU on Chrome with low fps screen sharing (#1570)

* fix: high CPU on Chrome with low fps screen sharing

It turns out that if 5 fps is set on the track constraints,
Chrome will capture the original video in 30 fps and only
further down the pipeline will downsample it to 5 fps.
This results in very high CPU usage. Specify max FPS in
getDisplayMedia to fix the problem.

Getting rid of track.applyConstraints should also fix another
issue on Firefox where it reports 0x0 screen size after this call.

* ref(RTCUtils): remove trackOptions

* remove extra &&
tags/v0.0.2
Paweł Domas пре 4 година
родитељ
комит
ada0f5e537
No account linked to committer's email address
2 измењених фајлова са 23 додато и 65 уклоњено
  1. 6
    39
      modules/RTC/RTCUtils.js
  2. 17
    26
      modules/RTC/ScreenObtainer.js

+ 6
- 39
modules/RTC/RTCUtils.js Прегледај датотеку

@@ -485,28 +485,6 @@ function getSSConstraints(options = {}) {
485 485
     return constraints;
486 486
 }
487 487
 
488
-/**
489
- * Generates constraints for screen sharing when using getDisplayMedia.
490
- * The constraints(MediaTrackConstraints) are applied to the resulting track.
491
- *
492
- * @returns {Object} - MediaTrackConstraints constraints.
493
- */
494
-function getTrackSSConstraints(options = {}) {
495
-    // we used to set height and width in the constraints, but this can lead
496
-    // to inconsistencies if the browser is on a lower resolution screen
497
-    // and we share a screen with bigger resolution, so they are now not set
498
-    const constraints = {
499
-        frameRate: SS_DEFAULT_FRAME_RATE
500
-    };
501
-    const { desktopSharingFrameRate } = options;
502
-
503
-    if (desktopSharingFrameRate && desktopSharingFrameRate.max) {
504
-        constraints.frameRate = desktopSharingFrameRate.max;
505
-    }
506
-
507
-    return constraints;
508
-}
509
-
510 488
 /**
511 489
  * Updates the granted permissions based on the options we requested and the
512 490
  * streams we received.
@@ -1120,8 +1098,7 @@ class RTCUtils extends Listenable {
1120 1098
             desktopSharingSources: options.desktopSharingSources,
1121 1099
             gumOptions: {
1122 1100
                 frameRate: options.desktopSharingFrameRate
1123
-            },
1124
-            trackOptions: getTrackSSConstraints(options)
1101
+            }
1125 1102
         };
1126 1103
     }
1127 1104
 
@@ -1199,8 +1176,7 @@ class RTCUtils extends Listenable {
1199 1176
 
1200 1177
                 // Leverage the helper used by {@link _newGetDesktopMedia} to
1201 1178
                 // get constraints for the desktop stream.
1202
-                const { gumOptions, trackOptions }
1203
-                    = this._parseDesktopSharingOptions(otherOptions);
1179
+                const { gumOptions } = this._parseDesktopSharingOptions(otherOptions);
1204 1180
 
1205 1181
                 const constraints = {
1206 1182
                     video: {
@@ -1211,19 +1187,10 @@ class RTCUtils extends Listenable {
1211 1187
 
1212 1188
                 return this._getUserMedia(requestedDevices, constraints, timeout)
1213 1189
                     .then(stream => {
1214
-                        const track = stream && stream.getTracks()[0];
1215
-                        const applyConstrainsPromise
1216
-                            = track && track.applyConstraints
1217
-                                ? track.applyConstraints(trackOptions)
1218
-                                : Promise.resolve();
1219
-
1220
-                        return applyConstrainsPromise
1221
-                            .then(() => {
1222
-                                return {
1223
-                                    sourceType: 'device',
1224
-                                    stream
1225
-                                };
1226
-                            });
1190
+                        return {
1191
+                            sourceType: 'device',
1192
+                            stream
1193
+                        };
1227 1194
                     });
1228 1195
             }
1229 1196
 

+ 17
- 26
modules/RTC/ScreenObtainer.js Прегледај датотеку

@@ -152,8 +152,6 @@ const ScreenObtainer = {
152 152
      * @param errorCallback - The error callback.
153 153
      */
154 154
     obtainScreenFromGetDisplayMedia(options, callback, errorCallback) {
155
-        logger.info('Using getDisplayMedia for screen sharing');
156
-
157 155
         let getDisplayMedia;
158 156
 
159 157
         if (navigator.getDisplayMedia) {
@@ -171,32 +169,25 @@ const ScreenObtainer = {
171 169
             noiseSuppression: false
172 170
         } : true;
173 171
 
174
-        getDisplayMedia({
175
-            video: true,
172
+        const video = Object.keys(options.gumOptions).length > 0 ? options.gumOptions : true;
173
+
174
+        // At the time of this writing 'min' constraint for fps is not supported by getDisplayMedia.
175
+        video.frameRate && delete video.frameRate.min;
176
+
177
+        const constraints = {
178
+            video,
176 179
             audio,
177 180
             cursor: 'always'
178
-        })
179
-            .then(stream => {
180
-                let applyConstraintsPromise;
181
-
182
-                if (stream
183
-                    && stream.getTracks()
184
-                    && stream.getTracks().length > 0) {
185
-                    const videoTrack = stream.getVideoTracks()[0];
186
-
187
-                    // Apply video track constraint.
188
-                    if (videoTrack) {
189
-                        applyConstraintsPromise = videoTrack.applyConstraints(options.trackOptions);
190
-                    }
191
-                } else {
192
-                    applyConstraintsPromise = Promise.resolve();
193
-                }
181
+        };
182
+
183
+        logger.info('Using getDisplayMedia for screen sharing', constraints);
194 184
 
195
-                applyConstraintsPromise.then(() =>
196
-                    callback({
197
-                        stream,
198
-                        sourceId: stream.id
199
-                    }));
185
+        getDisplayMedia(constraints)
186
+            .then(stream => {
187
+                callback({
188
+                    stream,
189
+                    sourceId: stream.id
190
+                });
200 191
             })
201 192
             .catch(error => {
202 193
                 const errorDetails = {
@@ -205,7 +196,7 @@ const ScreenObtainer = {
205 196
                     errorStack: error && error.stack
206 197
                 };
207 198
 
208
-                logger.error('getDisplayMedia error', errorDetails);
199
+                logger.error('getDisplayMedia error', constraints, errorDetails);
209 200
 
210 201
                 if (errorDetails.errorMsg && errorDetails.errorMsg.indexOf('denied by system') !== -1) {
211 202
                     // On Chrome this is the only thing different between error returned when user cancels

Loading…
Откажи
Сачувај