1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
<!DOCTYPE HTML>
<html>
<head>
<script type="application/javascript" src="pc.js"></script>
<script type="application/javascript" src="sdpUtils.js"></script>
</head>
<body>
<pre id="test">
<script type="application/javascript">
createHTML({
bug: "1873801",
title: "Test that weird codec priorities don't trip us up",
visible: true
});
function makeCodecTopPriority({type, sdp}, codec) {
const ptToMove = sdputils.findCodecId(sdp, codec);
return {type, sdp: sdp.replace(
// m=video port type pts ptToMove more-pts?
new RegExp(`(m=video [^ ]+ [^ ]+)(.*)( ${ptToMove})( [^ ]+)?`, "g"),
'$1$3$2$4')};
}
function isCodecFirst(sdp, codec) {
const pt = sdputils.findCodecId(sdp, codec);
return !!sdp.match(`m=video [^ ]+ [^ ]+ ${pt}\w`);
}
async function checkTopPriorityOffer(codec, isPseudoCodec) {
const pc1 = new RTCPeerConnection();
const pc2 = new RTCPeerConnection();
const stream = await navigator.mediaDevices.getUserMedia({ video: true });
const sender = pc1.addTrack(stream.getTracks()[0]);
await pc1.setLocalDescription();
const mungedOffer = makeCodecTopPriority(pc1.localDescription, codec);
await pc2.setRemoteDescription(mungedOffer);
await pc2.setLocalDescription();
await pc1.setRemoteDescription(pc2.localDescription);
is(isCodecFirst((await pc2.createOffer()).sdp, codec), !isPseudoCodec,
"Top-priority codecs should come first in reoffers, unless they are pseudo codecs (eg; ulpfec)");
}
async function checkTopPriorityAnswer(codec, isPseudoCodec) {
const pc1 = new RTCPeerConnection();
const pc2 = new RTCPeerConnection();
const stream = await navigator.mediaDevices.getUserMedia({ video: true });
const sender = pc1.addTrack(stream.getTracks()[0]);
await pc1.setLocalDescription();
await pc2.setRemoteDescription(pc1.localDescription);
await pc2.setLocalDescription();
const mungedAnswer = makeCodecTopPriority(pc2.localDescription, codec);
await pc1.setRemoteDescription(mungedAnswer);
is(isCodecFirst((await pc1.createOffer()).sdp, codec), !isPseudoCodec,
"Top-priority codecs should come first in reoffers, unless they are pseudo codecs (eg; ulpfec)");
}
const tests = [
async function checkTopPriorityUlpfecInOffer() {
await checkTopPriorityOffer("ulpfec", true);
},
async function checkTopPriorityUlpfecInAnswer() {
await checkTopPriorityAnswer("ulpfec", true);
},
async function checkTopPriorityUlpfecInOffer() {
await checkTopPriorityOffer("red", true);
},
async function checkTopPriorityUlpfecInAnswer() {
await checkTopPriorityAnswer("red", true);
},
async function checkTopPriorityUlpfecInOffer() {
await checkTopPriorityOffer("rtx", true);
},
async function checkTopPriorityUlpfecInAnswer() {
await checkTopPriorityAnswer("rtx", true);
},
];
runNetworkTest(async () => {
for (const test of tests) {
info(`Running test: ${test.name}`);
await test();
info(`Done running test: ${test.name}`);
}
});
</script>
</pre>
</body>
</html>
|