Преглед на файлове

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
     return constraints;
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
  * Updates the granted permissions based on the options we requested and the
489
  * Updates the granted permissions based on the options we requested and the
512
  * streams we received.
490
  * streams we received.
1120
             desktopSharingSources: options.desktopSharingSources,
1098
             desktopSharingSources: options.desktopSharingSources,
1121
             gumOptions: {
1099
             gumOptions: {
1122
                 frameRate: options.desktopSharingFrameRate
1100
                 frameRate: options.desktopSharingFrameRate
1123
-            },
1124
-            trackOptions: getTrackSSConstraints(options)
1101
+            }
1125
         };
1102
         };
1126
     }
1103
     }
1127
 
1104
 
1199
 
1176
 
1200
                 // Leverage the helper used by {@link _newGetDesktopMedia} to
1177
                 // Leverage the helper used by {@link _newGetDesktopMedia} to
1201
                 // get constraints for the desktop stream.
1178
                 // get constraints for the desktop stream.
1202
-                const { gumOptions, trackOptions }
1203
-                    = this._parseDesktopSharingOptions(otherOptions);
1179
+                const { gumOptions } = this._parseDesktopSharingOptions(otherOptions);
1204
 
1180
 
1205
                 const constraints = {
1181
                 const constraints = {
1206
                     video: {
1182
                     video: {
1211
 
1187
 
1212
                 return this._getUserMedia(requestedDevices, constraints, timeout)
1188
                 return this._getUserMedia(requestedDevices, constraints, timeout)
1213
                     .then(stream => {
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
      * @param errorCallback - The error callback.
152
      * @param errorCallback - The error callback.
153
      */
153
      */
154
     obtainScreenFromGetDisplayMedia(options, callback, errorCallback) {
154
     obtainScreenFromGetDisplayMedia(options, callback, errorCallback) {
155
-        logger.info('Using getDisplayMedia for screen sharing');
156
-
157
         let getDisplayMedia;
155
         let getDisplayMedia;
158
 
156
 
159
         if (navigator.getDisplayMedia) {
157
         if (navigator.getDisplayMedia) {
171
             noiseSuppression: false
169
             noiseSuppression: false
172
         } : true;
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
             audio,
179
             audio,
177
             cursor: 'always'
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
             .catch(error => {
192
             .catch(error => {
202
                 const errorDetails = {
193
                 const errorDetails = {
205
                     errorStack: error && error.stack
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
                 if (errorDetails.errorMsg && errorDetails.errorMsg.indexOf('denied by system') !== -1) {
201
                 if (errorDetails.errorMsg && errorDetails.errorMsg.indexOf('denied by system') !== -1) {
211
                     // On Chrome this is the only thing different between error returned when user cancels
202
                     // On Chrome this is the only thing different between error returned when user cancels

Loading…
Отказ
Запис