|
@@ -11,7 +11,7 @@ import * as SDPUtil from "./SDPUtil";
|
11
|
11
|
* @returns {number} the number of video ssrcs in the given sdp
|
12
|
12
|
*/
|
13
|
13
|
function numVideoSsrcs (parsedSdp) {
|
14
|
|
- let videoMLine = parsedSdp.media.find(m => m.type === "video");
|
|
14
|
+ const videoMLine = parsedSdp.media.find(m => m.type === "video");
|
15
|
15
|
return videoMLine.ssrcs
|
16
|
16
|
.map(ssrcInfo => ssrcInfo.id)
|
17
|
17
|
.filter((ssrc, index, array) => array.indexOf(ssrc) === index)
|
|
@@ -24,7 +24,7 @@ function numVideoSsrcs (parsedSdp) {
|
24
|
24
|
* @returns {number} the primary video ssrc in the given sdp
|
25
|
25
|
*/
|
26
|
26
|
function getPrimaryVideoSsrc (parsedSdp) {
|
27
|
|
- let videoMLine = parsedSdp.media.find(m => m.type === "video");
|
|
27
|
+ const videoMLine = parsedSdp.media.find(m => m.type === "video");
|
28
|
28
|
return parseInt(SDPUtil.parsePrimaryVideoSsrc(videoMLine));
|
29
|
29
|
}
|
30
|
30
|
|
|
@@ -37,15 +37,15 @@ function getPrimaryVideoSsrc (parsedSdp) {
|
37
|
37
|
* @returns {list<number>} the primary video ssrcs in the given sdp
|
38
|
38
|
*/
|
39
|
39
|
function getPrimaryVideoSsrcs (parsedSdp) {
|
40
|
|
- let videoMLine = parsedSdp.media.find(m => m.type === "video");
|
|
40
|
+ const videoMLine = parsedSdp.media.find(m => m.type === "video");
|
41
|
41
|
if (numVideoSsrcs(parsedSdp) === 1) {
|
42
|
42
|
return [videoMLine.ssrcs[0].id];
|
43
|
43
|
} else {
|
44
|
|
- let simGroups = getVideoGroups(parsedSdp, "SIM");
|
|
44
|
+ const simGroups = getVideoGroups(parsedSdp, "SIM");
|
45
|
45
|
if (simGroups.length > 1) {
|
46
|
46
|
return;
|
47
|
47
|
}
|
48
|
|
- let simGroup = simGroups[0];
|
|
48
|
+ const simGroup = simGroups[0];
|
49
|
49
|
return SDPUtil.parseGroupSsrcs(simGroup);
|
50
|
50
|
}
|
51
|
51
|
}
|
|
@@ -60,7 +60,7 @@ function getPrimaryVideoSsrcs (parsedSdp) {
|
60
|
60
|
* that matched the passed semantics
|
61
|
61
|
*/
|
62
|
62
|
function getVideoGroups (parsedSdp, groupSemantics) {
|
63
|
|
- let videoMLine = parsedSdp.media.find(m => m.type === "video");
|
|
63
|
+ const videoMLine = parsedSdp.media.find(m => m.type === "video");
|
64
|
64
|
videoMLine.ssrcGroups = videoMLine.ssrcGroups || [];
|
65
|
65
|
return videoMLine.ssrcGroups
|
66
|
66
|
.filter(g => g.semantics === groupSemantics);
|
|
@@ -82,18 +82,18 @@ describe ("RtxModifier", function() {
|
82
|
82
|
it ("should add a single rtx ssrc", function() {
|
83
|
83
|
// Call rtxModifier.modifyRtxSsrcs with an sdp that contains a single video
|
84
|
84
|
// ssrc. The returned sdp should have an rtx ssrc and an fid group.
|
85
|
|
- let newSdpStr = this.rtxModifier.modifyRtxSsrcs(this.transform.write(this.singleVideoSdp));
|
86
|
|
- let newSdp = transform.parse(newSdpStr);
|
87
|
|
- let newPrimaryVideoSsrc = getPrimaryVideoSsrc(newSdp);
|
|
85
|
+ const newSdpStr = this.rtxModifier.modifyRtxSsrcs(this.transform.write(this.singleVideoSdp));
|
|
86
|
+ const newSdp = transform.parse(newSdpStr);
|
|
87
|
+ const newPrimaryVideoSsrc = getPrimaryVideoSsrc(newSdp);
|
88
|
88
|
expect(newPrimaryVideoSsrc).toEqual(this.primaryVideoSsrc);
|
89
|
89
|
// Should now have an rtx ssrc as well
|
90
|
90
|
expect(numVideoSsrcs(newSdp)).toEqual(2);
|
91
|
91
|
// Should now have an FID group
|
92
|
|
- let fidGroups = getVideoGroups(newSdp, "FID");
|
|
92
|
+ const fidGroups = getVideoGroups(newSdp, "FID");
|
93
|
93
|
expect(fidGroups.length).toEqual(1);
|
94
|
94
|
|
95
|
|
- let fidGroup = fidGroups[0];
|
96
|
|
- let fidGroupPrimarySsrc = SDPUtil.parseGroupSsrcs(fidGroup)[0];
|
|
95
|
+ const fidGroup = fidGroups[0];
|
|
96
|
+ const fidGroupPrimarySsrc = SDPUtil.parseGroupSsrcs(fidGroup)[0];
|
97
|
97
|
expect(fidGroupPrimarySsrc).toEqual(this.primaryVideoSsrc);
|
98
|
98
|
});
|
99
|
99
|
|
|
@@ -105,13 +105,13 @@ describe ("RtxModifier", function() {
|
105
|
105
|
let newSdp = transform.parse(newSdpStr);
|
106
|
106
|
|
107
|
107
|
let fidGroup = getVideoGroups(newSdp, "FID")[0];
|
108
|
|
- let fidGroupRtxSsrc = SDPUtil.parseGroupSsrcs(fidGroup)[1];
|
|
108
|
+ const fidGroupRtxSsrc = SDPUtil.parseGroupSsrcs(fidGroup)[1];
|
109
|
109
|
|
110
|
110
|
// Now pass the original sdp through again
|
111
|
111
|
newSdpStr = this.rtxModifier.modifyRtxSsrcs(this.transform.write(this.singleVideoSdp));
|
112
|
112
|
newSdp = transform.parse(newSdpStr);
|
113
|
113
|
fidGroup = getVideoGroups(newSdp, "FID")[0];
|
114
|
|
- let newFidGroupRtxSsrc = SDPUtil.parseGroupSsrcs(fidGroup)[1];
|
|
114
|
+ const newFidGroupRtxSsrc = SDPUtil.parseGroupSsrcs(fidGroup)[1];
|
115
|
115
|
expect(newFidGroupRtxSsrc).toEqual(fidGroupRtxSsrc);
|
116
|
116
|
});
|
117
|
117
|
|
|
@@ -124,14 +124,14 @@ describe ("RtxModifier", function() {
|
124
|
124
|
let newSdp = transform.parse(newSdpStr);
|
125
|
125
|
|
126
|
126
|
let fidGroup = getVideoGroups(newSdp, "FID")[0];
|
127
|
|
- let fidGroupRtxSsrc = SDPUtil.parseGroupSsrcs(fidGroup)[1];
|
|
127
|
+ const fidGroupRtxSsrc = SDPUtil.parseGroupSsrcs(fidGroup)[1];
|
128
|
128
|
this.rtxModifier.clearSsrcCache();
|
129
|
129
|
|
130
|
130
|
// Now pass the original sdp through again
|
131
|
131
|
newSdpStr = this.rtxModifier.modifyRtxSsrcs(this.transform.write(this.singleVideoSdp));
|
132
|
132
|
newSdp = transform.parse(newSdpStr);
|
133
|
133
|
fidGroup = getVideoGroups(newSdp, "FID")[0];
|
134
|
|
- let newFidGroupRtxSsrc = SDPUtil.parseGroupSsrcs(fidGroup)[1];
|
|
134
|
+ const newFidGroupRtxSsrc = SDPUtil.parseGroupSsrcs(fidGroup)[1];
|
135
|
135
|
expect(newFidGroupRtxSsrc).not.toEqual(fidGroupRtxSsrc);
|
136
|
136
|
});
|
137
|
137
|
|
|
@@ -139,15 +139,15 @@ describe ("RtxModifier", function() {
|
139
|
139
|
// Manually set an rtx ssrc mapping in the cache
|
140
|
140
|
// Call modifyRtxSsrcs
|
141
|
141
|
// -->The rtx ssrc used should be the one we set
|
142
|
|
- let forcedRtxSsrc = 123456;
|
143
|
|
- let ssrcCache = new Map();
|
|
142
|
+ const forcedRtxSsrc = 123456;
|
|
143
|
+ const ssrcCache = new Map();
|
144
|
144
|
ssrcCache.set(this.primaryVideoSsrc, forcedRtxSsrc);
|
145
|
145
|
this.rtxModifier.setSsrcCache(ssrcCache);
|
146
|
|
- let newSdpStr = this.rtxModifier.modifyRtxSsrcs(this.transform.write(this.singleVideoSdp));
|
147
|
|
- let newSdp = transform.parse(newSdpStr);
|
|
146
|
+ const newSdpStr = this.rtxModifier.modifyRtxSsrcs(this.transform.write(this.singleVideoSdp));
|
|
147
|
+ const newSdp = transform.parse(newSdpStr);
|
148
|
148
|
|
149
|
|
- let fidGroup = getVideoGroups(newSdp, "FID")[0];
|
150
|
|
- let fidGroupRtxSsrc = SDPUtil.parseGroupSsrcs(fidGroup)[1];
|
|
149
|
+ const fidGroup = getVideoGroups(newSdp, "FID")[0];
|
|
150
|
+ const fidGroupRtxSsrc = SDPUtil.parseGroupSsrcs(fidGroup)[1];
|
151
|
151
|
expect(fidGroupRtxSsrc).toEqual(forcedRtxSsrc);
|
152
|
152
|
});
|
153
|
153
|
});
|
|
@@ -161,17 +161,17 @@ describe ("RtxModifier", function() {
|
161
|
161
|
it ("should add rtx ssrcs for all of them", function() {
|
162
|
162
|
// Call rtxModifier.modifyRtxSsrcs with an sdp that contains multiple video
|
163
|
163
|
// ssrcs. The returned sdp should have an rtx ssrc and an fid group for all of them.
|
164
|
|
- let newSdpStr = this.rtxModifier.modifyRtxSsrcs(this.transform.write(this.multipleVideoSdp));
|
165
|
|
- let newSdp = transform.parse(newSdpStr);
|
166
|
|
- let newPrimaryVideoSsrcs = getPrimaryVideoSsrcs(newSdp);
|
|
164
|
+ const newSdpStr = this.rtxModifier.modifyRtxSsrcs(this.transform.write(this.multipleVideoSdp));
|
|
165
|
+ const newSdp = transform.parse(newSdpStr);
|
|
166
|
+ const newPrimaryVideoSsrcs = getPrimaryVideoSsrcs(newSdp);
|
167
|
167
|
expect(newPrimaryVideoSsrcs).toEqual(this.primaryVideoSsrcs);
|
168
|
168
|
// Should now have rtx ssrcs as well
|
169
|
169
|
expect(numVideoSsrcs(newSdp)).toEqual(this.primaryVideoSsrcs.length * 2);
|
170
|
170
|
// Should now have FID groups
|
171
|
|
- let fidGroups = getVideoGroups(newSdp, "FID");
|
|
171
|
+ const fidGroups = getVideoGroups(newSdp, "FID");
|
172
|
172
|
expect(fidGroups.length).toEqual(this.primaryVideoSsrcs.length);
|
173
|
173
|
fidGroups.forEach(fidGroup => {
|
174
|
|
- let fidGroupPrimarySsrc = SDPUtil.parseGroupSsrcs(fidGroup)[0];
|
|
174
|
+ const fidGroupPrimarySsrc = SDPUtil.parseGroupSsrcs(fidGroup)[0];
|
175
|
175
|
expect(this.primaryVideoSsrcs.indexOf(fidGroupPrimarySsrc)).not.toEqual(-1);
|
176
|
176
|
});
|
177
|
177
|
});
|
|
@@ -183,13 +183,13 @@ describe ("RtxModifier", function() {
|
183
|
183
|
let newSdpStr = this.rtxModifier.modifyRtxSsrcs(this.transform.write(this.multipleVideoSdp));
|
184
|
184
|
let newSdp = transform.parse(newSdpStr);
|
185
|
185
|
|
186
|
|
- let rtxMapping = new Map();
|
|
186
|
+ const rtxMapping = new Map();
|
187
|
187
|
let fidGroups = getVideoGroups(newSdp, "FID");
|
188
|
188
|
// Save the first mapping that is made
|
189
|
189
|
fidGroups.forEach(fidGroup => {
|
190
|
|
- let fidSsrcs = SDPUtil.parseGroupSsrcs(fidGroup);
|
191
|
|
- let fidGroupPrimarySsrc = fidSsrcs[0];
|
192
|
|
- let fidGroupRtxSsrc = fidSsrcs[1];
|
|
190
|
+ const fidSsrcs = SDPUtil.parseGroupSsrcs(fidGroup);
|
|
191
|
+ const fidGroupPrimarySsrc = fidSsrcs[0];
|
|
192
|
+ const fidGroupRtxSsrc = fidSsrcs[1];
|
193
|
193
|
rtxMapping.set(fidGroupPrimarySsrc, fidGroupRtxSsrc);
|
194
|
194
|
});
|
195
|
195
|
// Now pass the original sdp through again and make sure we get the same mapping
|
|
@@ -197,9 +197,9 @@ describe ("RtxModifier", function() {
|
197
|
197
|
newSdp = transform.parse(newSdpStr);
|
198
|
198
|
fidGroups = getVideoGroups(newSdp, "FID");
|
199
|
199
|
fidGroups.forEach(fidGroup => {
|
200
|
|
- let fidSsrcs = SDPUtil.parseGroupSsrcs(fidGroup);
|
201
|
|
- let fidGroupPrimarySsrc = fidSsrcs[0];
|
202
|
|
- let fidGroupRtxSsrc = fidSsrcs[1];
|
|
200
|
+ const fidSsrcs = SDPUtil.parseGroupSsrcs(fidGroup);
|
|
201
|
+ const fidGroupPrimarySsrc = fidSsrcs[0];
|
|
202
|
+ const fidGroupRtxSsrc = fidSsrcs[1];
|
203
|
203
|
expect(rtxMapping.has(fidGroupPrimarySsrc)).toBe(true);
|
204
|
204
|
expect(rtxMapping.get(fidGroupPrimarySsrc)).toEqual(fidGroupRtxSsrc);
|
205
|
205
|
});
|
|
@@ -213,13 +213,13 @@ describe ("RtxModifier", function() {
|
213
|
213
|
let newSdpStr = this.rtxModifier.modifyRtxSsrcs(this.transform.write(this.multipleVideoSdp));
|
214
|
214
|
let newSdp = transform.parse(newSdpStr);
|
215
|
215
|
|
216
|
|
- let rtxMapping = new Map();
|
|
216
|
+ const rtxMapping = new Map();
|
217
|
217
|
let fidGroups = getVideoGroups(newSdp, "FID");
|
218
|
218
|
// Save the first mapping that is made
|
219
|
219
|
fidGroups.forEach(fidGroup => {
|
220
|
|
- let fidSsrcs = SDPUtil.parseGroupSsrcs(fidGroup);
|
221
|
|
- let fidGroupPrimarySsrc = fidSsrcs[0];
|
222
|
|
- let fidGroupRtxSsrc = fidSsrcs[1];
|
|
220
|
+ const fidSsrcs = SDPUtil.parseGroupSsrcs(fidGroup);
|
|
221
|
+ const fidGroupPrimarySsrc = fidSsrcs[0];
|
|
222
|
+ const fidGroupRtxSsrc = fidSsrcs[1];
|
223
|
223
|
rtxMapping.set(fidGroupPrimarySsrc, fidGroupRtxSsrc);
|
224
|
224
|
});
|
225
|
225
|
|
|
@@ -229,9 +229,9 @@ describe ("RtxModifier", function() {
|
229
|
229
|
newSdp = transform.parse(newSdpStr);
|
230
|
230
|
fidGroups = getVideoGroups(newSdp, "FID");
|
231
|
231
|
fidGroups.forEach(fidGroup => {
|
232
|
|
- let fidSsrcs = SDPUtil.parseGroupSsrcs(fidGroup);
|
233
|
|
- let fidGroupPrimarySsrc = fidSsrcs[0];
|
234
|
|
- let fidGroupRtxSsrc = fidSsrcs[1];
|
|
232
|
+ const fidSsrcs = SDPUtil.parseGroupSsrcs(fidGroup);
|
|
233
|
+ const fidGroupPrimarySsrc = fidSsrcs[0];
|
|
234
|
+ const fidGroupRtxSsrc = fidSsrcs[1];
|
235
|
235
|
expect(rtxMapping.has(fidGroupPrimarySsrc)).toBe(true);
|
236
|
236
|
expect(rtxMapping.get(fidGroupPrimarySsrc)).not.toEqual(fidGroupRtxSsrc);
|
237
|
237
|
});
|
|
@@ -241,20 +241,20 @@ describe ("RtxModifier", function() {
|
241
|
241
|
// Manually set an rtx ssrc mapping in the cache
|
242
|
242
|
// Call modifyRtxSsrcs
|
243
|
243
|
// -->The rtx ssrc used should be the one we set
|
244
|
|
- let rtxMapping = new Map();
|
|
244
|
+ const rtxMapping = new Map();
|
245
|
245
|
this.primaryVideoSsrcs.forEach(ssrc => {
|
246
|
246
|
rtxMapping.set(ssrc, SDPUtil.generateSsrc());
|
247
|
247
|
});
|
248
|
248
|
this.rtxModifier.setSsrcCache(rtxMapping);
|
249
|
249
|
|
250
|
|
- let newSdpStr = this.rtxModifier.modifyRtxSsrcs(this.transform.write(this.multipleVideoSdp));
|
251
|
|
- let newSdp = transform.parse(newSdpStr);
|
|
250
|
+ const newSdpStr = this.rtxModifier.modifyRtxSsrcs(this.transform.write(this.multipleVideoSdp));
|
|
251
|
+ const newSdp = transform.parse(newSdpStr);
|
252
|
252
|
|
253
|
|
- let fidGroups = getVideoGroups(newSdp, "FID");
|
|
253
|
+ const fidGroups = getVideoGroups(newSdp, "FID");
|
254
|
254
|
fidGroups.forEach(fidGroup => {
|
255
|
|
- let fidSsrcs = SDPUtil.parseGroupSsrcs(fidGroup);
|
256
|
|
- let fidGroupPrimarySsrc = fidSsrcs[0];
|
257
|
|
- let fidGroupRtxSsrc = fidSsrcs[1];
|
|
255
|
+ const fidSsrcs = SDPUtil.parseGroupSsrcs(fidGroup);
|
|
256
|
+ const fidGroupPrimarySsrc = fidSsrcs[0];
|
|
257
|
+ const fidGroupRtxSsrc = fidSsrcs[1];
|
258
|
258
|
expect(rtxMapping.has(fidGroupPrimarySsrc)).toBe(true);
|
259
|
259
|
expect(rtxMapping.get(fidGroupPrimarySsrc)).toEqual(fidGroupRtxSsrc);
|
260
|
260
|
});
|
|
@@ -263,26 +263,26 @@ describe ("RtxModifier", function() {
|
263
|
263
|
|
264
|
264
|
describe ("(corner cases)", function() {
|
265
|
265
|
it ("should handle a recvonly video mline", function() {
|
266
|
|
- let sdp = SampleSdpStrings.plainVideoSdp;
|
267
|
|
- let videoMLine = sdp.media.find(m => m.type === "video");
|
|
266
|
+ const sdp = SampleSdpStrings.plainVideoSdp;
|
|
267
|
+ const videoMLine = sdp.media.find(m => m.type === "video");
|
268
|
268
|
videoMLine.direction = "recvonly";
|
269
|
|
- let newSdpStr = this.rtxModifier.modifyRtxSsrcs(this.transform.write(sdp));
|
|
269
|
+ const newSdpStr = this.rtxModifier.modifyRtxSsrcs(this.transform.write(sdp));
|
270
|
270
|
expect(newSdpStr).toEqual(this.transform.write(sdp));
|
271
|
271
|
});
|
272
|
272
|
|
273
|
273
|
it ("should handle an inactive video mline", function() {
|
274
|
|
- let sdp = SampleSdpStrings.plainVideoSdp;
|
275
|
|
- let videoMLine = sdp.media.find(m => m.type === "video");
|
|
274
|
+ const sdp = SampleSdpStrings.plainVideoSdp;
|
|
275
|
+ const videoMLine = sdp.media.find(m => m.type === "video");
|
276
|
276
|
videoMLine.direction = "inactive";
|
277
|
|
- let newSdpStr = this.rtxModifier.modifyRtxSsrcs(this.transform.write(sdp));
|
|
277
|
+ const newSdpStr = this.rtxModifier.modifyRtxSsrcs(this.transform.write(sdp));
|
278
|
278
|
expect(newSdpStr).toEqual(this.transform.write(sdp));
|
279
|
279
|
});
|
280
|
280
|
|
281
|
281
|
it ("should handle a video mline with no video ssrcs", function() {
|
282
|
|
- let sdp = SampleSdpStrings.plainVideoSdp;
|
283
|
|
- let videoMLine = sdp.media.find(m => m.type === "video");
|
|
282
|
+ const sdp = SampleSdpStrings.plainVideoSdp;
|
|
283
|
+ const videoMLine = sdp.media.find(m => m.type === "video");
|
284
|
284
|
videoMLine.ssrcs = [];
|
285
|
|
- let newSdpStr = this.rtxModifier.modifyRtxSsrcs(this.transform.write(sdp));
|
|
285
|
+ const newSdpStr = this.rtxModifier.modifyRtxSsrcs(this.transform.write(sdp));
|
286
|
286
|
expect(newSdpStr).toEqual(this.transform.write(sdp));
|
287
|
287
|
});
|
288
|
288
|
});
|