Skip to content

Commit

Permalink
webrtc wpt: update setCodecPreferences tests for spec changes
Browse files Browse the repository at this point in the history
tracking w3c/webrtc-pc#2926
* tests now use RTCRtpReceiver.getCapabilities instead of RTCRtpSender
* added test that a sendonly codec throws InvalidModificationError

WebRTC change:
  https://webrtc-review.googlesource.com/c/src/+/328780

BUG=webrtc:15396

Remove obsolete WebRtc-ExposeNonStandardStats feature

which broke when stats were moved to using WebIDL

BUG=chromium:1323230,chromium:1414363

Change-Id: I690b76caf171a8c5ace41badf3b66cd90ffb596d
  • Loading branch information
fippo authored and chromium-wpt-export-bot committed Jan 31, 2024
1 parent 3087c1e commit 53d716b
Showing 1 changed file with 40 additions and 49 deletions.
89 changes: 40 additions & 49 deletions webrtc/RTCRtpTransceiver-setCodecPreferences.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,6 @@
<script>
'use strict';

// Test is based on the following editor draft:
// https://w3c.github.io/webrtc-pc/archives/20170605/webrtc.html

/*
5.4. RTCRtpTransceiver Interface
interface RTCRtpTransceiver {
...
void setCodecPreferences(sequence<RTCRtpCodecCapability> codecs);
};
setCodecPreferences
- Setting codecs to an empty sequence resets codec preferences to any
default value.
- The codecs sequence passed into setCodecPreferences can only contain
codecs that are returned by RTCRtpSender.getCapabilities(kind) or
RTCRtpReceiver.getCapabilities(kind), where kind is the kind of the
RTCRtpTransceiver on which the method is called. Additionally, the
RTCRtpCodecParameters dictionary members cannot be modified. If
codecs does not fulfill these requirements, the user agent MUST throw
an InvalidModificationError.
*/
/*
* Chromium note: this requires build bots with H264 support. See
* https://bugs.chromium.org/p/chromium/issues/detail?id=840659
Expand All @@ -39,9 +17,9 @@
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
const transceiver = pc.addTransceiver('audio');
const capabilities = RTCRtpSender.getCapabilities('audio');
const capabilities = RTCRtpReceiver.getCapabilities('audio');
transceiver.setCodecPreferences(capabilities.codecs);
}, `setCodecPreferences() on audio transceiver with codecs returned from RTCRtpSender.getCapabilities('audio') should succeed`);
}, `setCodecPreferences() on audio transceiver with codecs returned from RTCRtpReceiver.getCapabilities('audio') should succeed`);

test((t) => {
const pc = new RTCPeerConnection();
Expand All @@ -51,15 +29,6 @@
transceiver.setCodecPreferences(capabilities.codecs);
}, `setCodecPreferences() on video transceiver with codecs returned from RTCRtpReceiver.getCapabilities('video') should succeed`);

test((t) => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
const transceiver = pc.addTransceiver('audio');
const capabilities1 = RTCRtpSender.getCapabilities('audio');
const capabilities2 = RTCRtpReceiver.getCapabilities('audio');
transceiver.setCodecPreferences([...capabilities1.codecs, ... capabilities2.codecs]);
}, `setCodecPreferences() with both sender receiver codecs combined should succeed`);

test((t) => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
Expand All @@ -71,7 +40,7 @@
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
const transceiver = pc.addTransceiver('audio');
const capabilities = RTCRtpSender.getCapabilities('audio');
const capabilities = RTCRtpReceiver.getCapabilities('audio');
const { codecs } = capabilities;

if(codecs.length >= 2) {
Expand All @@ -87,7 +56,7 @@
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
const transceiver = pc.addTransceiver('video');
const capabilities = RTCRtpSender.getCapabilities('video');
const capabilities = RTCRtpReceiver.getCapabilities('video');
const { codecs } = capabilities;
// This test verifies that the mandatory VP8 codec is present
// and can be set.
Expand All @@ -104,7 +73,7 @@
test(() => {
const pc = new RTCPeerConnection();
const transceiver = pc.addTransceiver('video');
const capabilities = RTCRtpSender.getCapabilities('video');
const capabilities = RTCRtpReceiver.getCapabilities('video');
const { codecs } = capabilities;
// This test verifies that the mandatory H264 codec is present
// and can be set.
Expand All @@ -120,7 +89,7 @@

async function getRTPMapLinesWithCodecAsFirst(firstCodec)
{
const capabilities = RTCRtpSender.getCapabilities('video').codecs;
const capabilities = RTCRtpReceiver.getCapabilities('video').codecs;
capabilities.forEach((codec, idx) => {
if (codec.mimeType === firstCodec) {
capabilities.splice(idx, 1);
Expand All @@ -133,28 +102,28 @@
transceiver.setCodecPreferences(capabilities);
const offer = await pc.createOffer();

return offer.sdp.split('\r\n').filter(line => line.indexOf("a=rtpmap") === 0);
return offer.sdp.split('\r\n').filter(line => line.indexOf('a=rtpmap:') === 0);
}

promise_test(async () => {
const lines = await getRTPMapLinesWithCodecAsFirst('video/H264');

assert_greater_than(lines.length, 1);
assert_true(lines[0].indexOf("H264") !== -1, "H264 should be the first codec");
assert_true(lines[0].indexOf('H264') !== -1, 'H264 should be the first codec');
}, `setCodecPreferences() should allow setting H264 as first codec`);

promise_test(async () => {
const lines = await getRTPMapLinesWithCodecAsFirst('video/VP8');

assert_greater_than(lines.length, 1);
assert_true(lines[0].indexOf("VP8") !== -1, "VP8 should be the first codec");
assert_true(lines[0].indexOf('VP8') !== -1, 'VP8 should be the first codec');
}, `setCodecPreferences() should allow setting VP8 as first codec`);

test((t) => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
const transceiver = pc.addTransceiver('audio');
const capabilities = RTCRtpSender.getCapabilities('video');
const capabilities = RTCRtpReceiver.getCapabilities('video');
assert_throws_dom('InvalidModificationError', () => transceiver.setCodecPreferences(capabilities.codecs));
}, `setCodecPreferences() on audio transceiver with codecs returned from getCapabilities('video') should throw InvalidModificationError`);

Expand Down Expand Up @@ -190,7 +159,7 @@
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
const transceiver = pc.addTransceiver('audio');
const capabilities = RTCRtpSender.getCapabilities('audio');
const capabilities = RTCRtpReceiver.getCapabilities('audio');
const codecs = [
...capabilities.codecs,
{
Expand All @@ -207,7 +176,7 @@
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
const transceiver = pc.addTransceiver('audio');
const capabilities = RTCRtpSender.getCapabilities('audio');
const capabilities = RTCRtpReceiver.getCapabilities('audio');
const codecs = [capabilities.codecs[0]];
codecs[0].clockRate = codecs[0].clockRate / 2;

Expand All @@ -218,7 +187,7 @@
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
const transceiver = pc.addTransceiver('audio');
const capabilities = RTCRtpSender.getCapabilities('audio');
const capabilities = RTCRtpReceiver.getCapabilities('audio');
const codecs = [capabilities.codecs[0]];
codecs[0].channels = codecs[0].channels + 11;

Expand All @@ -229,7 +198,7 @@
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
const transceiver = pc.addTransceiver('audio');
const capabilities = RTCRtpSender.getCapabilities('audio');
const capabilities = RTCRtpReceiver.getCapabilities('audio');
const codecs = [capabilities.codecs[0]];
codecs[0].sdpFmtpLine = "modifiedparameter=1";

Expand All @@ -240,7 +209,7 @@
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
const transceiver = pc.addTransceiver('audio');
const capabilities = RTCRtpSender.getCapabilities('audio');
const capabilities = RTCRtpReceiver.getCapabilities('audio');

const { codecs } = capabilities;
assert_greater_than(codecs.length, 0,
Expand All @@ -253,11 +222,34 @@
assert_throws_dom('InvalidModificationError', () => transceiver.setCodecPreferences(codecs));
}, `setCodecPreferences() with modified codecs returned from getCapabilities() should throw InvalidModificationError`);

promise_test(async (t) => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
const transceiver = pc.addTransceiver('video');
const receive_capabilities = RTCRtpReceiver.getCapabilities('video');
const send_capabilities = RTCRtpSender.getCapabilities('video');
let sendonly_codec = undefined;
for (const send_codec of send_capabilities.codecs) {
const matching_receive_codec = receive_capabilities.codecs.find(receive_codec => {
return receive_codec.mimeType === send_codec.mimeType &&
receive_codec.clockRate === send_codec.clockRate &&
receive_codec.channels === send_codec.channels &&
receive_codec.sdpFmtpLine === send_codec.sdpFmtpLine;
});
if (!matching_receive_codec) {
sendonly_codec = send_codec;
break;
}
}
assert_true(!!sendonly_codec);
assert_throws_dom('InvalidModificationError', () => transceiver.setCodecPreferences([sendonly_codec]));
}, `setCodecPreferences() with a send-only codec should throw InvalidModificationError`);

promise_test(async (t) => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
const transceiver = pc.addTransceiver('audio');
const {codecs} = RTCRtpSender.getCapabilities('audio');
const {codecs} = RTCRtpReceiver.getCapabilities('audio');
// Reorder codecs, put PCMU/PCMA first.
let firstCodec;
let i;
Expand All @@ -283,7 +275,7 @@
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
const transceiver = pc.addTransceiver('video');
const {codecs} = RTCRtpSender.getCapabilities('video');
const {codecs} = RTCRtpReceiver.getCapabilities('video');
// Reorder codecs, swap H264 and VP8.
let vp8 = -1;
let h264 = -1;
Expand Down Expand Up @@ -318,5 +310,4 @@
const rtpParameters = SDPUtils.parseRtpParameters(mediaSection);
assert_equals(rtpParameters.codecs[0].name, firstCodec);
}, `setCodecPreferences() modifies the order of video codecs in createOffer`);

</script>

0 comments on commit 53d716b

Please sign in to comment.