Browse Source

Use insertable streams to drop all media when in lite mode. (#2178)

(Rather than moving streams to inactive in SDP.)
tags/v0.0.2
Jonathan Lennox 2 years ago
parent
commit
fc84561232
No account linked to committer's email address

+ 10
- 3
JitsiConference.js View File

@@ -28,6 +28,7 @@ import { E2EEncryption } from './modules/e2ee/E2EEncryption';
28 28
 import E2ePing from './modules/e2eping/e2eping';
29 29
 import Jvb121EventGenerator from './modules/event/Jvb121EventGenerator';
30 30
 import FeatureFlags from './modules/flags/FeatureFlags';
31
+import { LiteModeContext } from './modules/litemode/LiteModeContext';
31 32
 import ReceiveVideoController from './modules/qualitycontrol/ReceiveVideoController';
32 33
 import SendVideoController from './modules/qualitycontrol/SendVideoController';
33 34
 import RecordingManager from './modules/recording/RecordingManager';
@@ -282,6 +283,12 @@ export default function JitsiConference(options) {
282 283
         this._e2eEncryption = new E2EEncryption(this);
283 284
     }
284 285
 
286
+    if (FeatureFlags.isRunInLiteModeEnabled()) {
287
+        logger.info('Lite mode enabled');
288
+
289
+        this._liteModeContext = new LiteModeContext(this);
290
+    }
291
+
285 292
     /**
286 293
      * Flag set to <tt>true</tt> when Jicofo sends a presence message indicating that the max audio sender limit has
287 294
      * been reached for the call. Once this is set, unmuting audio will be disabled from the client until it gets reset
@@ -2246,7 +2253,7 @@ JitsiConference.prototype._acceptJvbIncomingCall = function(jingleSession, jingl
2246 2253
             this._signalingLayer,
2247 2254
             {
2248 2255
                 ...this.options.config,
2249
-                enableInsertableStreams: this.isE2EEEnabled()
2256
+                enableInsertableStreams: this.isE2EEEnabled() || FeatureFlags.isRunInLiteModeEnabled()
2250 2257
             });
2251 2258
     } catch (error) {
2252 2259
         GlobalOnErrorHandler.callErrorHandler(error);
@@ -3005,7 +3012,7 @@ JitsiConference.prototype._acceptP2PIncomingCall = function(jingleSession, jingl
3005 3012
         this._signalingLayer,
3006 3013
         {
3007 3014
             ...this.options.config,
3008
-            enableInsertableStreams: this.isE2EEEnabled()
3015
+            enableInsertableStreams: this.isE2EEEnabled() || FeatureFlags.isRunInLiteModeEnabled()
3009 3016
         });
3010 3017
 
3011 3018
     logger.info('Starting CallStats for P2P connection...');
@@ -3373,7 +3380,7 @@ JitsiConference.prototype._startP2PSession = function(remoteJid) {
3373 3380
         this._signalingLayer,
3374 3381
         {
3375 3382
             ...this.options.config,
3376
-            enableInsertableStreams: this.isE2EEEnabled()
3383
+            enableInsertableStreams: this.isE2EEEnabled() || FeatureFlags.isRunInLiteModeEnabled()
3377 3384
         });
3378 3385
 
3379 3386
     logger.info('Starting CallStats for P2P connection...');

+ 0
- 4
modules/RTC/TraceablePeerConnection.js View File

@@ -2525,10 +2525,6 @@ TraceablePeerConnection.prototype.setRemoteDescription = function(description) {
2525 2525
 
2526 2526
             remoteDescription = this.interop.toUnifiedPlan(remoteDescription, currentDescription);
2527 2527
             this.trace('setRemoteDescription::postTransform (Unified)', dumpSDP(remoteDescription));
2528
-
2529
-            if (FeatureFlags.isRunInLiteModeEnabled()) {
2530
-                remoteDescription = this._mungeInactive(remoteDescription);
2531
-            }
2532 2528
         }
2533 2529
         if (this.isSimulcastOn()) {
2534 2530
             remoteDescription = this.tpcUtils.insertUnifiedPlanSimulcastReceive(remoteDescription);

+ 3
- 3
modules/flags/FeatureFlags.js View File

@@ -28,13 +28,13 @@ class FeatureFlags {
28 28
 
29 29
     /**
30 30
      * Checks if the run in lite mode is enabled.
31
-     * This will cause any media to be received and not decoded. (Directions are inactive and no ssrc and ssrc-groups
32
-     * are added to the remote description). This can be used for various test scenarios.
31
+     * This will cause any media to be received and not decoded. (Insertable streams are used to discard
32
+     * all media before it is decoded). This can be used for various test scenarios.
33 33
      *
34 34
      * @returns {boolean}
35 35
      */
36 36
     isRunInLiteModeEnabled() {
37
-        return this._runInLiteMode;
37
+        return this._runInLiteMode && browser.supportsInsertableStreams();
38 38
     }
39 39
 
40 40
     /**

+ 65
- 0
modules/litemode/LiteModeContext.js View File

@@ -0,0 +1,65 @@
1
+/* global TransformStream */
2
+import { getLogger } from '@jitsi/logger';
3
+
4
+import RTCEvents from '../../service/RTC/RTCEvents';
5
+import FeatureFlags from '../flags/FeatureFlags';
6
+
7
+// Flag to set on receivers to avoid setting up the lite mode
8
+// more than once.
9
+const kJitsiLiteMode = Symbol('kJitsiLiteMode');
10
+
11
+const logger = getLogger(__filename);
12
+
13
+/**
14
+ * This module implements a discard-all insertable stream.  Use to reduce decoder CPU load for testing.
15
+ */
16
+export class LiteModeContext {
17
+    /**
18
+     * A constructor.
19
+     * @param {JitsiConference} conference - The conference instance for which lite mode is to be enabled.
20
+     */
21
+    constructor(conference) {
22
+        this.enabled = FeatureFlags.isRunInLiteModeEnabled();
23
+        if (!this.enabled) {
24
+            return;
25
+        }
26
+
27
+        conference.rtc.on(
28
+            RTCEvents.REMOTE_TRACK_ADDED,
29
+            (track, tpc) => this._setupLiteModeForTrack(tpc, track));
30
+    }
31
+
32
+    /**
33
+     * Setup Lite Mode for a track.
34
+     *
35
+     * @private
36
+     */
37
+    _setupLiteModeForTrack(tpc, track) {
38
+        if (!this.enabled) {
39
+            return;
40
+        }
41
+
42
+        const receiver = tpc.findReceiverForTrack(track.track);
43
+
44
+        if (!receiver) {
45
+            logger.warn(`Could not set up lite mode for ${track}: receiver not found in: ${tpc}`);
46
+
47
+            return;
48
+        }
49
+
50
+        if (receiver[kJitsiLiteMode]) {
51
+            return;
52
+        }
53
+        receiver[kJitsiLiteMode] = true;
54
+
55
+        const receiverStreams = receiver.createEncodedStreams();
56
+
57
+        const transformStream = new TransformStream({
58
+            transform: () => {
59
+                // Don't call controller.enqueue(encodedFrame), and so drop everything
60
+            }
61
+        });
62
+
63
+        receiverStreams.readable.pipeThrough(transformStream).pipeTo(receiverStreams.writable);
64
+    }
65
+}

Loading…
Cancel
Save