Selaa lähdekoodia

ref(TPC): Add extra checks before updating RTCRtpEncodingParameters.

Check if all the relevant fields are correctly configured instead of checking for just the encode resolution on the local video sender.
release-8443
Jaya Allamsetty 1 vuosi sitten
vanhempi
commit
4e93e8663b
2 muutettua tiedostoa jossa 38 lisäystä ja 89 poistoa
  1. 0
    60
      modules/RTC/TPCUtils.js
  2. 38
    29
      modules/RTC/TraceablePeerConnection.js

+ 0
- 60
modules/RTC/TPCUtils.js Näytä tiedosto

@@ -578,66 +578,6 @@ export class TPCUtils {
578 578
         });
579 579
     }
580 580
 
581
-    /**
582
-     * Returns the max resolution that the client is configured to encode for a given local video track. The actual
583
-     * send resolution might be downscaled based on cpu and bandwidth constraints.
584
-     *
585
-     * @param {JitsiLocalTrack} localVideoTrack - The local video track.
586
-     * @param {CodecMimeType} codec - The codec currently in use.
587
-     * @returns {number|null} The max encoded resolution for the given video track.
588
-     */
589
-    getConfiguredEncodeResolution(localVideoTrack, codec) {
590
-        const height = localVideoTrack.getCaptureResolution();
591
-        const videoSender = this.pc.findSenderForTrack(localVideoTrack.getTrack());
592
-        let maxHeight = 0;
593
-
594
-        if (!videoSender) {
595
-            return null;
596
-        }
597
-        const parameters = videoSender.getParameters();
598
-
599
-        if (!parameters?.encodings?.length) {
600
-            return null;
601
-        }
602
-
603
-        // SVC mode for VP9 and AV1 codecs.
604
-        if (this._isRunningInFullSvcMode(codec)) {
605
-            const activeEncoding = parameters.encodings[0];
606
-
607
-            if (activeEncoding.active) {
608
-                return height / activeEncoding.scaleResolutionDownBy;
609
-            }
610
-
611
-            return null;
612
-        }
613
-
614
-        const hasIncorrectConfig = this.pc._capScreenshareBitrate
615
-            ? parameters.encodings.every(encoding => encoding.active)
616
-            : parameters.encodings.some(encoding => !encoding.active);
617
-
618
-        // Check if every encoding is active for screenshare track when low fps screenshare is configured or some
619
-        // of the encodings are disabled when high fps screenshare is configured. In both these cases, the track
620
-        // encodings need to be reconfigured. This is needed when p2p->jvb switch happens and new sender constraints
621
-        // are not received by the client.
622
-        if (localVideoTrack.getVideoType() === VideoType.DESKTOP && hasIncorrectConfig) {
623
-            return null;
624
-        }
625
-
626
-        for (const encoding in parameters.encodings) {
627
-            if (parameters.encodings[encoding].active) {
628
-                const encodingConfig = this._getVideoStreamEncodings(localVideoTrack, codec);
629
-                const scaleResolutionDownBy
630
-                    = this.pc.isSpatialScalabilityOn()
631
-                        ? encodingConfig[encoding].scaleResolutionDownBy
632
-                        : parameters.encodings[encoding].scaleResolutionDownBy;
633
-
634
-                maxHeight = Math.max(maxHeight, height / scaleResolutionDownBy);
635
-            }
636
-        }
637
-
638
-        return maxHeight;
639
-    }
640
-
641 581
     /**
642 582
      * Takes in a *unified plan* offer and inserts the appropriate parameters for adding simulcast receive support.
643 583
      * @param {Object} desc - A session description object

+ 38
- 29
modules/RTC/TraceablePeerConnection.js Näytä tiedosto

@@ -2222,22 +2222,6 @@ TraceablePeerConnection.prototype.setSenderVideoConstraints = function(frameHeig
2222 2222
         return Promise.resolve();
2223 2223
     }
2224 2224
 
2225
-    const configuredResolution = this.tpcUtils.getConfiguredEncodeResolution(
2226
-        localVideoTrack,
2227
-        this.getConfiguredVideoCodec());
2228
-
2229
-    // Ignore sender constraints if the client is already sending video of the requested resolution. Note that for
2230
-    // screensharing sources, the max resolution will be the height of the window being captured irrespective of the
2231
-    // height being requested by the peer.
2232
-    if ((localVideoTrack.getVideoType() === VideoType.CAMERA && configuredResolution === frameHeight)
2233
-        || (localVideoTrack.getVideoType() === VideoType.DESKTOP
2234
-            && frameHeight > 0
2235
-            && configuredResolution === localVideoTrack.getCaptureResolution())) {
2236
-        return Promise.resolve();
2237
-    }
2238
-
2239
-    this._senderMaxHeights.set(sourceName, frameHeight);
2240
-
2241 2225
     return this._updateVideoSenderParameters(
2242 2226
         () => this._updateVideoSenderEncodings(frameHeight, localVideoTrack));
2243 2227
 };
@@ -2286,22 +2270,32 @@ TraceablePeerConnection.prototype._updateVideoSenderEncodings = function(frameHe
2286 2270
         : DEGRADATION_PREFERENCE_CAMERA; // Prefer frame-rate for high fps share and camera.
2287 2271
 
2288 2272
     parameters.degradationPreference = preference;
2289
-    logger.info(`${this} Setting degradation preference [preference=${preference},track=${localVideoTrack}`);
2290 2273
 
2291 2274
     // Calculate the encodings active state based on the resolution requested by the bridge.
2292 2275
     const codec = this.getConfiguredVideoCodec();
2293
-    const maxBitrates = this.tpcUtils.calculateEncodingsBitrates(localVideoTrack, codec, frameHeight);
2294
-    const encodingsActiveState = this.tpcUtils.calculateEncodingsActiveState(localVideoTrack, codec, frameHeight);
2295
-    const scaleFactor = this.tpcUtils.calculateEncodingsScaleFactor(localVideoTrack, codec, frameHeight);
2276
+    const bitrates = this.tpcUtils.calculateEncodingsBitrates(localVideoTrack, codec, frameHeight);
2277
+    const activeState = this.tpcUtils.calculateEncodingsActiveState(localVideoTrack, codec, frameHeight);
2278
+    const scaleFactors = this.tpcUtils.calculateEncodingsScaleFactor(localVideoTrack, codec, frameHeight);
2296 2279
     const scalabilityModes = this.tpcUtils.calculateEncodingsScalabilityMode(localVideoTrack, codec, frameHeight);
2297
-
2298
-    for (const encoding in parameters.encodings) {
2299
-        if (parameters.encodings.hasOwnProperty(encoding)) {
2300
-            parameters.encodings[encoding].active = encodingsActiveState[encoding];
2280
+    let needsUpdate = false;
2281
+
2282
+    for (const idx in parameters.encodings) {
2283
+        if (parameters.encodings.hasOwnProperty(idx)) {
2284
+            const {
2285
+                active = undefined,
2286
+                maxBitrate = undefined,
2287
+                scalabilityMode = undefined,
2288
+                scaleResolutionDownBy = undefined
2289
+            } = parameters.encodings[idx];
2290
+
2291
+            if (active !== activeState[idx]) {
2292
+                parameters.encodings[idx].active = activeState[idx];
2293
+                needsUpdate = true;
2294
+            }
2301 2295
 
2302 2296
             // Firefox doesn't follow the spec and lets application specify the degradation preference on the
2303 2297
             // encodings.
2304
-            browser.isFirefox() && (parameters.encodings[encoding].degradationPreference = preference);
2298
+            browser.isFirefox() && (parameters.encodings[idx].degradationPreference = preference);
2305 2299
 
2306 2300
             // Do not configure 'scaleResolutionDownBy' and 'maxBitrate' for encoders running in legacy K-SVC mode
2307 2301
             // since the browser sends only the lowest resolution layer when those are configured.
@@ -2309,21 +2303,36 @@ TraceablePeerConnection.prototype._updateVideoSenderEncodings = function(frameHe
2309 2303
                 || !this.isSpatialScalabilityOn()
2310 2304
                 || (browser.supportsScalabilityModeAPI()
2311 2305
                     && this.tpcUtils.codecSettings[codec].scalabilityModeEnabled)) {
2312
-                parameters.encodings[encoding].scaleResolutionDownBy = scaleFactor[encoding];
2313
-                parameters.encodings[encoding].maxBitrate = maxBitrates[encoding];
2306
+                if (scaleResolutionDownBy !== scaleFactors[idx]) {
2307
+                    parameters.encodings[idx].scaleResolutionDownBy = scaleFactors[idx];
2308
+                    needsUpdate = true;
2309
+                }
2310
+                if (maxBitrate !== bitrates[idx]) {
2311
+                    parameters.encodings[idx].maxBitrate = bitrates[idx];
2312
+                    needsUpdate = true;
2313
+                }
2314 2314
             }
2315 2315
 
2316 2316
             // Configure scalability mode when its supported and enabled.
2317 2317
             if (scalabilityModes) {
2318
-                parameters.encodings[encoding].scalabilityMode = scalabilityModes[encoding];
2318
+                if (scalabilityMode !== scalabilityModes[idx]) {
2319
+                    parameters.encodings[idx].scalabilityMode = scalabilityModes[idx];
2320
+                    needsUpdate = true;
2321
+                }
2319 2322
             } else {
2320
-                parameters.encodings[encoding].scalabilityMode = undefined;
2323
+                parameters.encodings[idx].scalabilityMode = undefined;
2321 2324
             }
2322 2325
         }
2323 2326
     }
2327
+
2328
+    if (!needsUpdate) {
2329
+        return Promise.resolve();
2330
+    }
2331
+
2324 2332
     logger.info(`${this} setting max height=${frameHeight},encodings=${JSON.stringify(parameters.encodings)}`);
2325 2333
 
2326 2334
     return videoSender.setParameters(parameters).then(() => {
2335
+        this._senderMaxHeights.set(localVideoTrack.getSourceName(), frameHeight);
2327 2336
         localVideoTrack.maxEnabledResolution = frameHeight;
2328 2337
         this.eventEmitter.emit(RTCEvents.LOCAL_TRACK_MAX_ENABLED_RESOLUTION_CHANGED, localVideoTrack);
2329 2338
     });

Loading…
Peruuta
Tallenna