Skip to content

Commit f13fab3

Browse files
fippochromium-wpt-export-bot
authored andcommitted
webrtc wpt: add test for direction-based filtering of codecs
to supplement the discussion in w3c/webrtc-pc#2937 BUG=324930413 Change-Id: Iebf02aade64030e11590af211fa7bc90f976c592
1 parent c5e5bdb commit f13fab3

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<!doctype html>
2+
<meta charset=utf-8>
3+
<meta name="timeout" content="long">
4+
<title>RTCPeerConnection Codecs in offer get filtered by direction</title>
5+
<script src="/resources/testharness.js"></script>
6+
<script src="/resources/testharnessreport.js"></script>
7+
<script src="../third_party/sdp/sdp.js"></script>
8+
<script>
9+
'use strict';
10+
11+
function codecEquals(c1, c2) {
12+
return c1.mimeType === c2.mimeType &&
13+
c1.sdpFmtpLine === c2.sdpFmtpLine &&
14+
c1.clockRate === c2.clockRate &&
15+
c1.channels === c2.channels;
16+
}
17+
18+
function splitCodecs() {
19+
const sendCodecs = RTCRtpSender.getCapabilities('video').codecs;
20+
const receiveCodecs = RTCRtpReceiver.getCapabilities('video').codecs;
21+
const codecs = {
22+
sendrecv: [],
23+
sendonly: [],
24+
recvonly: [],
25+
};
26+
// Ignore RTX since it is present in capabilities once and has no apt.
27+
for (const sendCodec of sendCodecs) {
28+
if (sendCodec.mimeType === 'video/rtx') continue;
29+
if (receiveCodecs.find(receiveCodec => codecEquals(sendCodec, receiveCodec))) {
30+
codecs.sendrecv.push(sendCodec);
31+
}
32+
}
33+
34+
for (const sendCodec of sendCodecs) {
35+
if (sendCodec.mimeType === 'video/rtx') continue;
36+
if (!receiveCodecs.find(receiveCodec => codecEquals(sendCodec, receiveCodec))) {
37+
codecs.sendonly.push(sendCodec);
38+
}
39+
}
40+
for (const receiveCodec of receiveCodecs) {
41+
if (receiveCodec.mimeType === 'video/rtx') continue;
42+
if (!sendCodecs.find(sendCodec => codecEquals(sendCodec, receiveCodec))) {
43+
codecs.recvonly.push(receiveCodec);
44+
}
45+
}
46+
return codecs;
47+
}
48+
49+
promise_test(async t => {
50+
const pc = new RTCPeerConnection();
51+
t.add_cleanup(() => pc.close());
52+
53+
const allCodecs = splitCodecs();
54+
const transceiver = pc.addTransceiver('video');
55+
56+
transceiver.direction = 'sendrecv';
57+
let offer = await pc.createOffer();
58+
let mediaSection = SDPUtils.getMediaSections(offer.sdp)[0];
59+
let rtpParameters = SDPUtils.parseRtpParameters(mediaSection);
60+
const sendrecvCodecs = rtpParameters.codecs.filter(c => c.name !== 'rtx');
61+
assert_equals(sendrecvCodecs.length, allCodecs.sendrecv.length);
62+
}, 'Codecs get filtered by direction for sendrecv');
63+
64+
promise_test(async t => {
65+
const pc = new RTCPeerConnection();
66+
t.add_cleanup(() => pc.close());
67+
68+
const allCodecs = splitCodecs();
69+
const transceiver = pc.addTransceiver('video');
70+
71+
transceiver.direction = 'sendonly'
72+
const offer = await pc.createOffer();
73+
const mediaSection = SDPUtils.getMediaSections(offer.sdp)[0];
74+
const rtpParameters = SDPUtils.parseRtpParameters(mediaSection);
75+
const sendonlyCodecs = rtpParameters.codecs.filter(c => c.name !== 'rtx');
76+
assert_equals(sendonlyCodecs.length, allCodecs.sendrecv.length + allCodecs.sendonly.length);
77+
}, 'Codecs get filtered by direction for sendonly');
78+
79+
promise_test(async t => {
80+
const pc = new RTCPeerConnection();
81+
t.add_cleanup(() => pc.close());
82+
83+
const allCodecs = splitCodecs();
84+
const transceiver = pc.addTransceiver('video');
85+
86+
transceiver.direction = 'recvonly'
87+
const offer = await pc.createOffer();
88+
const mediaSection = SDPUtils.getMediaSections(offer.sdp)[0];
89+
const rtpParameters = SDPUtils.parseRtpParameters(mediaSection);
90+
const recvonlyCodecs = rtpParameters.codecs.filter(c => c.name !== 'rtx');
91+
assert_equals(recvonlyCodecs.length, allCodecs.sendrecv.length + allCodecs.recvonly.length);
92+
}, 'Codecs get filtered by direction for recvonly');
93+
94+
</script>

0 commit comments

Comments
 (0)