Browse Source

Minor simulcast code cleanup.

master
George Politis 10 years ago
parent
commit
00606da9d2
1 changed files with 229 additions and 254 deletions
  1. 229
    254
      simulcast.js

+ 229
- 254
simulcast.js View File

3
 
3
 
4
 /**
4
 /**
5
  * Created by gp on 11/08/14.
5
  * Created by gp on 11/08/14.
6
+ *
7
+ * TODO(gp) split into SimulcastReceiver and SimulcastSender
6
  */
8
  */
7
 function Simulcast() {
9
 function Simulcast() {
8
     "use strict";
10
     "use strict";
15
 Simulcast.prototype = {
17
 Simulcast.prototype = {
16
 
18
 
17
     // global state for all transformers.
19
     // global state for all transformers.
18
-    localExplosionMap: {},
19
-    localVideoSourceCache: '',
20
-    remoteVideoSourceCache: '',
21
-    remoteMaps: {
20
+    _localVideoSourceCache: '',
21
+    _remoteVideoSourceCache: '',
22
+    _remoteMaps: {
22
         msid2Quality: {},
23
         msid2Quality: {},
23
         ssrc2Msid: {},
24
         ssrc2Msid: {},
24
         receivingVideoStreams: {}
25
         receivingVideoStreams: {}
25
     },
26
     },
26
-    localMaps: {
27
-        msids: [],
28
-        msid2ssrc: {}
29
-    },
30
-    emptyCompoundIndex: {},
27
+    _emptyCompoundIndex: {},
31
 
28
 
32
     _generateGuid: (function () {
29
     _generateGuid: (function () {
33
         function s4() {
30
         function s4() {
43
     }()),
40
     }()),
44
 
41
 
45
     _cacheLocalVideoSources: function (lines) {
42
     _cacheLocalVideoSources: function (lines) {
46
-        this.localVideoSourceCache = this._getVideoSources(lines);
43
+        this._localVideoSourceCache = this._getVideoSources(lines);
47
     },
44
     },
48
 
45
 
49
     _restoreLocalVideoSources: function (lines) {
46
     _restoreLocalVideoSources: function (lines) {
50
-        this._replaceVideoSources(lines, this.localVideoSourceCache);
47
+        this._replaceVideoSources(lines, this._localVideoSourceCache);
51
     },
48
     },
52
 
49
 
53
     _cacheRemoteVideoSources: function (lines) {
50
     _cacheRemoteVideoSources: function (lines) {
54
-        this.remoteVideoSourceCache = this._getVideoSources(lines);
51
+        this._remoteVideoSourceCache = this._getVideoSources(lines);
55
     },
52
     },
56
 
53
 
57
     _restoreRemoteVideoSources: function (lines) {
54
     _restoreRemoteVideoSources: function (lines) {
58
-        this._replaceVideoSources(lines, this.remoteVideoSourceCache);
55
+        this._replaceVideoSources(lines, this._remoteVideoSourceCache);
59
     },
56
     },
60
 
57
 
61
     _replaceVideoSources: function (lines, videoSources) {
58
     _replaceVideoSources: function (lines, videoSources) {
197
 
194
 
198
     /**
195
     /**
199
      * The _indexOfArray() method returns the first a CompoundIndex at which a
196
      * The _indexOfArray() method returns the first a CompoundIndex at which a
200
-     * given element can be found in the array, or emptyCompoundIndex if it is
197
+     * given element can be found in the array, or _emptyCompoundIndex if it is
201
      * not present.
198
      * not present.
202
      *
199
      *
203
      * Example:
200
      * Example:
225
                 return {row: i, column: idx};
222
                 return {row: i, column: idx};
226
             }
223
             }
227
         }
224
         }
228
-        return this.emptyCompoundIndex;
225
+        return this._emptyCompoundIndex;
229
     },
226
     },
230
 
227
 
231
     _removeSimulcastGroup: function (lines) {
228
     _removeSimulcastGroup: function (lines) {
238
         }
235
         }
239
     },
236
     },
240
 
237
 
241
-    /**
242
-     * Produces a single stream with multiple tracks for local video sources.
243
-     *
244
-     * @param lines
245
-     * @private
246
-     */
247
-    _explodeLocalSimulcastSources: function (lines) {
248
-        var sb, msid, sid, tid, videoSources, self;
249
-
250
-        if (this.debugLvl) {
251
-            console.info('Exploding local video sources...');
252
-        }
253
-
254
-        videoSources = this._parseMedia(lines, ['video'])[0];
255
-
256
-        self = this;
257
-        if (videoSources.groups && videoSources.groups.length !== 0) {
258
-            videoSources.groups.forEach(function (group) {
259
-                if (group.semantics === 'SIM') {
260
-                    group.ssrcs.forEach(function (ssrc) {
261
-
262
-                        // Get the msid for this ssrc..
263
-                        if (self.localExplosionMap[ssrc]) {
264
-                            // .. either from the explosion map..
265
-                            msid = self.localExplosionMap[ssrc];
266
-                        } else {
267
-                            // .. or generate a new one (msid).
268
-                            sid = videoSources.sources[ssrc].msid
269
-                                .substring(0, videoSources.sources[ssrc].msid.indexOf(' '));
270
-
271
-                            tid = self._generateGuid();
272
-                            msid = [sid, tid].join(' ');
273
-                            self.localExplosionMap[ssrc] = msid;
274
-                        }
275
-
276
-                        // Assign it to the source object.
277
-                        videoSources.sources[ssrc].msid = msid;
278
-
279
-                        // TODO(gp) Change the msid of associated sources.
280
-                    });
281
-                }
282
-            });
283
-        }
284
-
285
-        sb = this._compileVideoSources(videoSources);
286
-
287
-        this._replaceVideoSources(lines, sb);
288
-    },
289
-
290
-    /**
291
-     * Groups local video sources together in the ssrc-group:SIM group.
292
-     *
293
-     * @param lines
294
-     * @private
295
-     */
296
-    _groupLocalVideoSources: function (lines) {
297
-        var sb, videoSources, ssrcs = [], ssrc;
298
-
299
-        if (this.debugLvl) {
300
-            console.info('Grouping local video sources...');
301
-        }
302
-
303
-        videoSources = this._parseMedia(lines, ['video'])[0];
304
-
305
-        for (ssrc in videoSources.sources) {
306
-            // jitsi-meet destroys/creates streams at various places causing
307
-            // the original local stream ids to change. The only thing that
308
-            // remains unchanged is the trackid.
309
-            this.localMaps.msid2ssrc[videoSources.sources[ssrc].msid.split(' ')[1]] = ssrc;
310
-        }
311
-
312
-        var self = this;
313
-        // TODO(gp) add only "free" sources.
314
-        this.localMaps.msids.forEach(function (msid) {
315
-            ssrcs.push(self.localMaps.msid2ssrc[msid]);
316
-        });
317
-
318
-        if (!videoSources.groups) {
319
-            videoSources.groups = [];
320
-        }
321
-
322
-        videoSources.groups.push({
323
-            'semantics': 'SIM',
324
-            'ssrcs': ssrcs
325
-        });
326
-
327
-        sb = this._compileVideoSources(videoSources);
328
-
329
-        this._replaceVideoSources(lines, sb);
330
-    },
331
-
332
     _appendSimulcastGroup: function (lines) {
238
     _appendSimulcastGroup: function (lines) {
333
         var videoSources, ssrcGroup, simSSRC, numOfSubs = 2, i, sb, msid;
239
         var videoSources, ssrcGroup, simSSRC, numOfSubs = 2, i, sb, msid;
334
 
240
 
367
         this._replaceVideoSources(lines, sb);
273
         this._replaceVideoSources(lines, sb);
368
     },
274
     },
369
 
275
 
370
-// Does the actual patching.
276
+    // Does the actual patching.
371
     _ensureSimulcastGroup: function (lines) {
277
     _ensureSimulcastGroup: function (lines) {
372
         if (this.debugLvl) {
278
         if (this.debugLvl) {
373
             console.info('Ensuring simulcast group...');
279
             console.info('Ensuring simulcast group...');
374
         }
280
         }
375
 
281
 
376
-        if (this._indexOfArray('a=ssrc-group:SIM', lines) === this.emptyCompoundIndex) {
282
+        if (this._indexOfArray('a=ssrc-group:SIM', lines) === this._emptyCompoundIndex) {
377
             this._appendSimulcastGroup(lines);
283
             this._appendSimulcastGroup(lines);
378
             this._cacheLocalVideoSources(lines);
284
             this._cacheLocalVideoSources(lines);
379
         } else {
285
         } else {
389
             console.info('Ensuring x-google-conference flag...')
295
             console.info('Ensuring x-google-conference flag...')
390
         }
296
         }
391
 
297
 
392
-        if (this._indexOfArray('a=x-google-flag:conference', lines) === this.emptyCompoundIndex) {
298
+        if (this._indexOfArray('a=x-google-flag:conference', lines) === this._emptyCompoundIndex) {
393
             // Add the google conference flag
299
             // Add the google conference flag
394
             sb = this._getVideoSources(lines);
300
             sb = this._getVideoSources(lines);
395
             sb = ['a=x-google-flag:conference'].concat(sb);
301
             sb = ['a=x-google-flag:conference'].concat(sb);
486
             videoSource, quality;
392
             videoSource, quality;
487
 
393
 
488
         // (re) initialize the remote maps.
394
         // (re) initialize the remote maps.
489
-        this.remoteMaps.msid2Quality = {};
490
-        this.remoteMaps.ssrc2Msid = {};
395
+        this._remoteMaps.msid2Quality = {};
396
+        this._remoteMaps.ssrc2Msid = {};
491
 
397
 
492
         var self = this;
398
         var self = this;
493
         if (remoteVideoSources.groups && remoteVideoSources.groups.length !== 0) {
399
         if (remoteVideoSources.groups && remoteVideoSources.groups.length !== 0) {
496
                     quality = 0;
402
                     quality = 0;
497
                     group.ssrcs.forEach(function (ssrc) {
403
                     group.ssrcs.forEach(function (ssrc) {
498
                         videoSource = remoteVideoSources.sources[ssrc];
404
                         videoSource = remoteVideoSources.sources[ssrc];
499
-                        self.remoteMaps.msid2Quality[videoSource.msid] = quality++;
500
-                        self.remoteMaps.ssrc2Msid[videoSource.ssrc] = videoSource.msid;
405
+                        self._remoteMaps.msid2Quality[videoSource.msid] = quality++;
406
+                        self._remoteMaps.ssrc2Msid[videoSource.ssrc] = videoSource.msid;
501
                     });
407
                     });
502
                 }
408
                 }
503
             });
409
             });
505
     },
411
     },
506
 
412
 
507
     _setReceivingVideoStream: function (endpoint, ssrc) {
413
     _setReceivingVideoStream: function (endpoint, ssrc) {
508
-        this.remoteMaps.receivingVideoStreams[endpoint] = ssrc;
414
+        this._remoteMaps.receivingVideoStreams[endpoint] = ssrc;
509
     },
415
     },
510
 
416
 
511
     /**
417
     /**
522
         if (config.enableSimulcast) {
428
         if (config.enableSimulcast) {
523
 
429
 
524
             stream.getVideoTracks().some(function (track) {
430
             stream.getVideoTracks().some(function (track) {
525
-                return Object.keys(self.remoteMaps.receivingVideoStreams).some(function (endpoint) {
526
-                    var ssrc = self.remoteMaps.receivingVideoStreams[endpoint];
527
-                    var msid = self.remoteMaps.ssrc2Msid[ssrc];
431
+                return Object.keys(self._remoteMaps.receivingVideoStreams).some(function (endpoint) {
432
+                    var ssrc = self._remoteMaps.receivingVideoStreams[endpoint];
433
+                    var msid = self._remoteMaps.ssrc2Msid[ssrc];
528
                     if (msid == [stream.id, track.id].join(' ')) {
434
                     if (msid == [stream.id, track.id].join(' ')) {
529
                         electedTrack = track;
435
                         electedTrack = track;
530
                         return true;
436
                         return true;
537
                 tracks = stream.getVideoTracks();
443
                 tracks = stream.getVideoTracks();
538
                 for (i = 0; i < tracks.length; i++) {
444
                 for (i = 0; i < tracks.length; i++) {
539
                     msid = [stream.id, tracks[i].id].join(' ');
445
                     msid = [stream.id, tracks[i].id].join(' ');
540
-                    if (this.remoteMaps.msid2Quality[msid] === quality) {
446
+                    if (this._remoteMaps.msid2Quality[msid] === quality) {
541
                         electedTrack = tracks[i];
447
                         electedTrack = tracks[i];
542
                         break;
448
                         break;
543
                     }
449
                     }
563
      * @returns {*}
469
      * @returns {*}
564
      */
470
      */
565
     getRemoteVideoStreamIdBySSRC: function (ssrc) {
471
     getRemoteVideoStreamIdBySSRC: function (ssrc) {
566
-        return this.remoteMaps.ssrc2Msid[ssrc];
472
+        return this._remoteMaps.ssrc2Msid[ssrc];
567
     },
473
     },
568
 
474
 
569
     parseMedia: function (desc, mediatypes) {
475
     parseMedia: function (desc, mediatypes) {
586
 
492
 
587
 NativeSimulcast.prototype = Object.create(Simulcast.prototype);
493
 NativeSimulcast.prototype = Object.create(Simulcast.prototype);
588
 
494
 
495
+NativeSimulcast.prototype._localExplosionMap = {};
496
+
497
+/**
498
+ * Produces a single stream with multiple tracks for local video sources.
499
+ *
500
+ * @param lines
501
+ * @private
502
+ */
503
+NativeSimulcast.prototype._explodeLocalSimulcastSources = function (lines) {
504
+    var sb, msid, sid, tid, videoSources, self;
505
+
506
+    if (this.debugLvl) {
507
+        console.info('Exploding local video sources...');
508
+    }
509
+
510
+    videoSources = this._parseMedia(lines, ['video'])[0];
511
+
512
+    self = this;
513
+    if (videoSources.groups && videoSources.groups.length !== 0) {
514
+        videoSources.groups.forEach(function (group) {
515
+            if (group.semantics === 'SIM') {
516
+                group.ssrcs.forEach(function (ssrc) {
517
+
518
+                    // Get the msid for this ssrc..
519
+                    if (self._localExplosionMap[ssrc]) {
520
+                        // .. either from the explosion map..
521
+                        msid = self._localExplosionMap[ssrc];
522
+                    } else {
523
+                        // .. or generate a new one (msid).
524
+                        sid = videoSources.sources[ssrc].msid
525
+                            .substring(0, videoSources.sources[ssrc].msid.indexOf(' '));
526
+
527
+                        tid = self._generateGuid();
528
+                        msid = [sid, tid].join(' ');
529
+                        self._localExplosionMap[ssrc] = msid;
530
+                    }
531
+
532
+                    // Assign it to the source object.
533
+                    videoSources.sources[ssrc].msid = msid;
534
+
535
+                    // TODO(gp) Change the msid of associated sources.
536
+                });
537
+            }
538
+        });
539
+    }
540
+
541
+    sb = this._compileVideoSources(videoSources);
542
+
543
+    this._replaceVideoSources(lines, sb);
544
+};
545
+
589
 /**
546
 /**
590
  * GUM for simulcast.
547
  * GUM for simulcast.
591
  *
548
  *
599
 
556
 
600
     var self = this;
557
     var self = this;
601
     navigator.webkitGetUserMedia(constraints, function (hqStream) {
558
     navigator.webkitGetUserMedia(constraints, function (hqStream) {
602
-
603
-        // reset local maps.
604
-        self.localMaps.msids = [];
605
-        self.localMaps.msid2ssrc = {};
606
-
607
-        // add hq stream to local map
608
-        self.localMaps.msids.push(hqStream.getVideoTracks()[0].id);
609
         self.localStream = hqStream;
559
         self.localStream = hqStream;
610
         success(hqStream);
560
         success(hqStream);
611
     }, err);
561
     }, err);
625
         return desc;
575
         return desc;
626
     }
576
     }
627
 
577
 
628
-    if (config.enableSimulcast) {
629
-        sb = desc.sdp.split('\r\n');
630
 
578
 
631
-        this._explodeLocalSimulcastSources(sb);
579
+    sb = desc.sdp.split('\r\n');
632
 
580
 
633
-        desc = new RTCSessionDescription({
634
-            type: desc.type,
635
-            sdp: sb.join('\r\n')
636
-        });
581
+    this._explodeLocalSimulcastSources(sb);
637
 
582
 
638
-        if (this.debugLvl && this.debugLvl > 1) {
639
-            console.info('Exploded local video sources');
640
-            console.info(desc.sdp);
641
-        }
583
+    desc = new RTCSessionDescription({
584
+        type: desc.type,
585
+        sdp: sb.join('\r\n')
586
+    });
587
+
588
+    if (this.debugLvl && this.debugLvl > 1) {
589
+        console.info('Exploded local video sources');
590
+        console.info(desc.sdp);
642
     }
591
     }
643
 
592
 
644
     return desc;
593
     return desc;
652
  * @returns {*}
601
  * @returns {*}
653
  */
602
  */
654
 NativeSimulcast.prototype.transformAnswer = function (desc) {
603
 NativeSimulcast.prototype.transformAnswer = function (desc) {
655
-    if (config.enableSimulcast) {
656
-
657
-        var sb = desc.sdp.split('\r\n');
658
-
659
-        // Even if we have enabled native simulcasting previously
660
-        // (with a call to SLD with an appropriate SDP, for example),
661
-        // createAnswer seems to consistently generate incomplete SDP
662
-        // with missing SSRCS.
663
-        //
664
-        // So, subsequent calls to SLD will have missing SSRCS and presence
665
-        // won't have the complete list of SRCs.
666
-        this._ensureSimulcastGroup(sb);
667
-
668
-        desc = new RTCSessionDescription({
669
-            type: desc.type,
670
-            sdp: sb.join('\r\n')
671
-        });
672
 
604
 
673
-        if (this.debugLvl && this.debugLvl > 1) {
674
-            console.info('Transformed answer');
675
-            console.info(desc.sdp);
676
-        }
605
+    var sb = desc.sdp.split('\r\n');
606
+
607
+    // Even if we have enabled native simulcasting previously
608
+    // (with a call to SLD with an appropriate SDP, for example),
609
+    // createAnswer seems to consistently generate incomplete SDP
610
+    // with missing SSRCS.
611
+    //
612
+    // So, subsequent calls to SLD will have missing SSRCS and presence
613
+    // won't have the complete list of SRCs.
614
+    this._ensureSimulcastGroup(sb);
615
+
616
+    desc = new RTCSessionDescription({
617
+        type: desc.type,
618
+        sdp: sb.join('\r\n')
619
+    });
620
+
621
+    if (this.debugLvl && this.debugLvl > 1) {
622
+        console.info('Transformed answer');
623
+        console.info(desc.sdp);
677
     }
624
     }
678
 
625
 
679
     return desc;
626
     return desc;
699
  * @returns {*}
646
  * @returns {*}
700
  */
647
  */
701
 NativeSimulcast.prototype.transformRemoteDescription = function (desc) {
648
 NativeSimulcast.prototype.transformRemoteDescription = function (desc) {
702
-    if (config.enableSimulcast) {
703
 
649
 
704
-        var sb = desc.sdp.split('\r\n');
650
+    var sb = desc.sdp.split('\r\n');
705
 
651
 
706
-        this._updateRemoteMaps(sb);
707
-        this._cacheRemoteVideoSources(sb);
708
-        this._removeSimulcastGroup(sb); // NOTE(gp) this needs to be called after updateRemoteMaps because we need the simulcast group in the _updateRemoteMaps() method.
709
-        // We don't need the goog conference flag if we're not doing
710
-        // native simulcast.
711
-        this._ensureGoogConference(sb);
652
+    this._updateRemoteMaps(sb);
653
+    this._cacheRemoteVideoSources(sb);
654
+    this._removeSimulcastGroup(sb); // NOTE(gp) this needs to be called after updateRemoteMaps because we need the simulcast group in the _updateRemoteMaps() method.
655
+    // We don't need the goog conference flag if we're not doing
656
+    // native simulcast.
657
+    this._ensureGoogConference(sb);
712
 
658
 
713
-        desc = new RTCSessionDescription({
714
-            type: desc.type,
715
-            sdp: sb.join('\r\n')
716
-        });
659
+    desc = new RTCSessionDescription({
660
+        type: desc.type,
661
+        sdp: sb.join('\r\n')
662
+    });
717
 
663
 
718
-        if (this.debugLvl && this.debugLvl > 1) {
719
-            console.info('Transformed remote description');
720
-            console.info(desc.sdp);
721
-        }
664
+    if (this.debugLvl && this.debugLvl > 1) {
665
+        console.info('Transformed remote description');
666
+        console.info(desc.sdp);
722
     }
667
     }
723
 
668
 
724
     return desc;
669
     return desc;
730
 
675
 
731
 NativeSimulcast.prototype.constructor = NativeSimulcast;
676
 NativeSimulcast.prototype.constructor = NativeSimulcast;
732
 
677
 
733
-function GrumpySimulcast() {
678
+function SimpleSimulcast() {
734
     Simulcast.call(this);
679
     Simulcast.call(this);
735
 }
680
 }
736
 
681
 
737
-GrumpySimulcast.prototype = Object.create(Simulcast.prototype);
682
+SimpleSimulcast.prototype = Object.create(Simulcast.prototype);
683
+
684
+SimpleSimulcast.prototype._localMaps = {
685
+    msids: [],
686
+    msid2ssrc: {}
687
+};
688
+
689
+/**
690
+ * Groups local video sources together in the ssrc-group:SIM group.
691
+ *
692
+ * @param lines
693
+ * @private
694
+ */
695
+SimpleSimulcast.prototype._groupLocalVideoSources = function (lines) {
696
+    var sb, videoSources, ssrcs = [], ssrc;
697
+
698
+    if (this.debugLvl) {
699
+        console.info('Grouping local video sources...');
700
+    }
701
+
702
+    videoSources = this._parseMedia(lines, ['video'])[0];
703
+
704
+    for (ssrc in videoSources.sources) {
705
+        // jitsi-meet destroys/creates streams at various places causing
706
+        // the original local stream ids to change. The only thing that
707
+        // remains unchanged is the trackid.
708
+        this._localMaps.msid2ssrc[videoSources.sources[ssrc].msid.split(' ')[1]] = ssrc;
709
+    }
710
+
711
+    var self = this;
712
+    // TODO(gp) add only "free" sources.
713
+    this._localMaps.msids.forEach(function (msid) {
714
+        ssrcs.push(self._localMaps.msid2ssrc[msid]);
715
+    });
716
+
717
+    if (!videoSources.groups) {
718
+        videoSources.groups = [];
719
+    }
720
+
721
+    videoSources.groups.push({
722
+        'semantics': 'SIM',
723
+        'ssrcs': ssrcs
724
+    });
725
+
726
+    sb = this._compileVideoSources(videoSources);
727
+
728
+    this._replaceVideoSources(lines, sb);
729
+};
738
 
730
 
739
 /**
731
 /**
740
  * GUM for simulcast.
732
  * GUM for simulcast.
743
  * @param success
735
  * @param success
744
  * @param err
736
  * @param err
745
  */
737
  */
746
-GrumpySimulcast.prototype.getUserMedia = function (constraints, success, err) {
738
+SimpleSimulcast.prototype.getUserMedia = function (constraints, success, err) {
747
 
739
 
748
     // TODO(gp) what if we request a resolution not supported by the hardware?
740
     // TODO(gp) what if we request a resolution not supported by the hardware?
749
     // TODO(gp) make the lq stream configurable; although this wouldn't work with native simulcast
741
     // TODO(gp) make the lq stream configurable; although this wouldn't work with native simulcast
761
     console.log('HQ constraints: ', constraints);
753
     console.log('HQ constraints: ', constraints);
762
     console.log('LQ constraints: ', lqConstraints);
754
     console.log('LQ constraints: ', lqConstraints);
763
 
755
 
764
-    if (config.enableSimulcast) {
765
 
756
 
766
-        // NOTE(gp) if we request the lq stream first webkitGetUserMedia
767
-        // fails randomly. Tested with Chrome 37. As fippo suggested, the
768
-        // reason appears to be that Chrome only acquires the cam once and
769
-        // then downscales the picture (https://code.google.com/p/chromium/issues/detail?id=346616#c11)
757
+    // NOTE(gp) if we request the lq stream first webkitGetUserMedia
758
+    // fails randomly. Tested with Chrome 37. As fippo suggested, the
759
+    // reason appears to be that Chrome only acquires the cam once and
760
+    // then downscales the picture (https://code.google.com/p/chromium/issues/detail?id=346616#c11)
770
 
761
 
771
-        var self = this;
772
-        navigator.webkitGetUserMedia(constraints, function (hqStream) {
762
+    var self = this;
763
+    navigator.webkitGetUserMedia(constraints, function (hqStream) {
773
 
764
 
774
-            self.localStream = hqStream;
765
+        self.localStream = hqStream;
775
 
766
 
776
-            // reset local maps.
777
-            self.localMaps.msids = [];
778
-            self.localMaps.msid2ssrc = {};
767
+        // reset local maps.
768
+        self._localMaps.msids = [];
769
+        self._localMaps.msid2ssrc = {};
779
 
770
 
780
-            // add hq trackid to local map
781
-            self.localMaps.msids.push(hqStream.getVideoTracks()[0].id);
771
+        // add hq trackid to local map
772
+        self._localMaps.msids.push(hqStream.getVideoTracks()[0].id);
782
 
773
 
783
-            navigator.webkitGetUserMedia(lqConstraints, function (lqStream) {
774
+        navigator.webkitGetUserMedia(lqConstraints, function (lqStream) {
784
 
775
 
785
-                self.displayedLocalVideoStream = lqStream;
776
+            self.displayedLocalVideoStream = lqStream;
786
 
777
 
787
-                // NOTE(gp) The specification says Array.forEach() will visit
788
-                // the array elements in numeric order, and that it doesn't
789
-                // visit elements that don't exist.
778
+            // NOTE(gp) The specification says Array.forEach() will visit
779
+            // the array elements in numeric order, and that it doesn't
780
+            // visit elements that don't exist.
790
 
781
 
791
-                // add lq trackid to local map
792
-                self.localMaps.msids.splice(0, 0, lqStream.getVideoTracks()[0].id);
782
+            // add lq trackid to local map
783
+            self._localMaps.msids.splice(0, 0, lqStream.getVideoTracks()[0].id);
793
 
784
 
794
-                self.localStream.addTrack(lqStream.getVideoTracks()[0]);
795
-                success(self.localStream);
796
-            }, err);
785
+            self.localStream.addTrack(lqStream.getVideoTracks()[0]);
786
+            success(self.localStream);
797
         }, err);
787
         }, err);
798
-    }
788
+    }, err);
799
 };
789
 };
800
 
790
 
801
 /**
791
 /**
805
  * @param desc
795
  * @param desc
806
  * @returns {RTCSessionDescription}
796
  * @returns {RTCSessionDescription}
807
  */
797
  */
808
-GrumpySimulcast.prototype.reverseTransformLocalDescription = function (desc) {
798
+SimpleSimulcast.prototype.reverseTransformLocalDescription = function (desc) {
809
     var sb;
799
     var sb;
810
 
800
 
811
     if (!desc || desc == null) {
801
     if (!desc || desc == null) {
812
         return desc;
802
         return desc;
813
     }
803
     }
814
 
804
 
815
-    if (config.enableSimulcast) {
816
-
805
+    sb = desc.sdp.split('\r\n');
817
 
806
 
818
-        sb = desc.sdp.split('\r\n');
807
+    this._groupLocalVideoSources(sb);
819
 
808
 
820
-        this._groupLocalVideoSources(sb);
821
-
822
-        desc = new RTCSessionDescription({
823
-            type: desc.type,
824
-            sdp: sb.join('\r\n')
825
-        });
809
+    desc = new RTCSessionDescription({
810
+        type: desc.type,
811
+        sdp: sb.join('\r\n')
812
+    });
826
 
813
 
827
-        if (this.debugLvl && this.debugLvl > 1) {
828
-            console.info('Grouped local video sources');
829
-            console.info(desc.sdp);
830
-        }
814
+    if (this.debugLvl && this.debugLvl > 1) {
815
+        console.info('Grouped local video sources');
816
+        console.info(desc.sdp);
831
     }
817
     }
832
 
818
 
833
     return desc;
819
     return desc;
840
  * @param desc
826
  * @param desc
841
  * @returns {*}
827
  * @returns {*}
842
  */
828
  */
843
-GrumpySimulcast.prototype.transformAnswer = function (desc) {
829
+SimpleSimulcast.prototype.transformAnswer = function (desc) {
844
     return desc;
830
     return desc;
845
 };
831
 };
846
 
832
 
851
  * @param desc
837
  * @param desc
852
  * @returns {*}
838
  * @returns {*}
853
  */
839
  */
854
-GrumpySimulcast.prototype.transformLocalDescription = function (desc) {
855
-    if (config.enableSimulcast) {
840
+SimpleSimulcast.prototype.transformLocalDescription = function (desc) {
856
 
841
 
857
-        var sb = desc.sdp.split('\r\n');
842
+    var sb = desc.sdp.split('\r\n');
858
 
843
 
859
-        this._removeSimulcastGroup(sb);
844
+    this._removeSimulcastGroup(sb);
860
 
845
 
861
-        desc = new RTCSessionDescription({
862
-            type: desc.type,
863
-            sdp: sb.join('\r\n')
864
-        });
846
+    desc = new RTCSessionDescription({
847
+        type: desc.type,
848
+        sdp: sb.join('\r\n')
849
+    });
865
 
850
 
866
-        if (this.debugLvl && this.debugLvl > 1) {
867
-            console.info('Transformed local description');
868
-            console.info(desc.sdp);
869
-        }
851
+    if (this.debugLvl && this.debugLvl > 1) {
852
+        console.info('Transformed local description');
853
+        console.info(desc.sdp);
870
     }
854
     }
871
 
855
 
872
     return desc;
856
     return desc;
880
  * @param desc
864
  * @param desc
881
  * @returns {*}
865
  * @returns {*}
882
  */
866
  */
883
-GrumpySimulcast.prototype.transformRemoteDescription = function (desc) {
884
-    if (config.enableSimulcast) {
867
+SimpleSimulcast.prototype.transformRemoteDescription = function (desc) {
885
 
868
 
886
-        var sb = desc.sdp.split('\r\n');
869
+    var sb = desc.sdp.split('\r\n');
887
 
870
 
888
-        this._updateRemoteMaps(sb);
889
-        this._cacheRemoteVideoSources(sb);
890
-        this._removeSimulcastGroup(sb); // NOTE(gp) this needs to be called after updateRemoteMaps because we need the simulcast group in the _updateRemoteMaps() method.
871
+    this._updateRemoteMaps(sb);
872
+    this._cacheRemoteVideoSources(sb);
873
+    this._removeSimulcastGroup(sb); // NOTE(gp) this needs to be called after updateRemoteMaps because we need the simulcast group in the _updateRemoteMaps() method.
891
 
874
 
892
-        desc = new RTCSessionDescription({
893
-            type: desc.type,
894
-            sdp: sb.join('\r\n')
895
-        });
875
+    desc = new RTCSessionDescription({
876
+        type: desc.type,
877
+        sdp: sb.join('\r\n')
878
+    });
896
 
879
 
897
-        if (this.debugLvl && this.debugLvl > 1) {
898
-            console.info('Transformed remote description');
899
-            console.info(desc.sdp);
900
-        }
880
+    if (this.debugLvl && this.debugLvl > 1) {
881
+        console.info('Transformed remote description');
882
+        console.info(desc.sdp);
901
     }
883
     }
902
 
884
 
903
     return desc;
885
     return desc;
904
 };
886
 };
905
 
887
 
906
-GrumpySimulcast.prototype._setLocalVideoStreamEnabled = function (ssrc, enabled) {
888
+SimpleSimulcast.prototype._setLocalVideoStreamEnabled = function (ssrc, enabled) {
907
     var trackid;
889
     var trackid;
908
 
890
 
909
     var self = this;
891
     var self = this;
910
     console.log(['Requested to', enabled ? 'enable' : 'disable', ssrc].join(' '));
892
     console.log(['Requested to', enabled ? 'enable' : 'disable', ssrc].join(' '));
911
-    if (Object.keys(this.localMaps.msid2ssrc).some(function (tid) {
893
+    if (Object.keys(this._localMaps.msid2ssrc).some(function (tid) {
912
         // Search for the track id that corresponds to the ssrc
894
         // Search for the track id that corresponds to the ssrc
913
-        if (self.localMaps.msid2ssrc[tid] == ssrc) {
895
+        if (self._localMaps.msid2ssrc[tid] == ssrc) {
914
             trackid = tid;
896
             trackid = tid;
915
             return true;
897
             return true;
916
         }
898
         }
930
     }
912
     }
931
 };
913
 };
932
 
914
 
933
-GrumpySimulcast.prototype.constructor = GrumpySimulcast;
915
+SimpleSimulcast.prototype.constructor = SimpleSimulcast;
934
 
916
 
935
 function NoSimulcast() {
917
 function NoSimulcast() {
936
     Simulcast.call(this);
918
     Simulcast.call(this);
948
 NoSimulcast.prototype.getUserMedia = function (constraints, success, err) {
930
 NoSimulcast.prototype.getUserMedia = function (constraints, success, err) {
949
     var self = this;
931
     var self = this;
950
     navigator.webkitGetUserMedia(constraints, function (hqStream) {
932
     navigator.webkitGetUserMedia(constraints, function (hqStream) {
951
-
952
-        // reset local maps.
953
-        self.localMaps.msids = [];
954
-        self.localMaps.msid2ssrc = {};
955
-
956
-        // add hq stream to local map
957
-        self.localMaps.msids.push(hqStream.getVideoTracks()[0].id);
958
-        self.displayedLocalVideoStream = self.localStream = hqStream;
933
+        self.localStream = hqStream;
959
         success(self.localStream);
934
         success(self.localStream);
960
     }, err);
935
     }, err);
961
 };
936
 };

Loading…
Cancel
Save