Skip to content

Commit

Permalink
webrtc wpt: update more tests to use receiver capabilities for setCod…
Browse files Browse the repository at this point in the history
…ecPreferences

BUG=webrtc:15396

Change-Id: Icb67eacc4554c5cf356b12ff7e7306ac795c4f34
  • Loading branch information
fippo authored and chromium-wpt-export-bot committed Feb 13, 2024
1 parent 279a195 commit 39ed5fa
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 82 deletions.
14 changes: 9 additions & 5 deletions webrtc-svc/RTCRtpParameters-scalability.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,17 @@
const param = transceiver.sender.getParameters();
const encoding = param.encodings[0];
assert_true('scalabilityMode' in encoding);

// If L3T3 is not supported at all, abort test.
assert_implements_optional(encoding.scalabilityMode === 'L3T3');
// Pick a codec known to not have L3T3 support
const capabilities = RTCRtpSender.getCapabilities('video');
const codec = capabilities.codecs.find(c => c.mimeType === 'video/VP8');
assert_true(codec !== undefined);
transceiver.setCodecPreferences([codec]);

pc2.ontrack = e => {
// Pick a codec known to not have L3T3 support.
const capabilities = RTCRtpReceiver.getCapabilities('video');
const codec = capabilities.codecs.find(c => c.mimeType === 'video/VP8');
assert_true(codec !== undefined);
e.transceiver.setCodecPreferences([codec]);
}
exchangeIceCandidates(pc1, pc2);
await exchangeOfferAnswer(pc1, pc2);
const sendParams = pc1.getSenders()[0].getParameters();
Expand Down
4 changes: 3 additions & 1 deletion webrtc-svc/svc-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ function createScalabilityTest(mimeType, scalabilityModes) {
const transceiver = pc1.addTransceiver(track1, {
sendEncodings: [{ scalabilityMode: scalabilityMode }],
});
transceiver.setCodecPreferences(RTCRtpSender.getCapabilities('video').codecs.filter(c => c.mimeType == mimeType));
pc2.addEventListener('track', e => {
e.transceiver.setCodecPreferences(RTCRtpReceiver.getCapabilities('video').codecs.filter(c => c.mimeType == mimeType));
});
const haveTrackEvent = new Promise(r => pc2.ontrack = r);
exchangeIceCandidates(pc1, pc2);
await exchangeOfferAnswer(pc1, pc2);
Expand Down
2 changes: 1 addition & 1 deletion webrtc/RTCPeerConnection-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ function findTransceiverForSender(pc, sender) {
}

function preferCodec(transceiver, mimeType, sdpFmtpLine) {
const {codecs} = RTCRtpSender.getCapabilities(transceiver.receiver.track.kind);
const {codecs} = RTCRtpReceiver.getCapabilities(transceiver.receiver.track.kind);
// sdpFmtpLine is optional, pick the first partial match if not given.
const selectedCodecIndex = codecs.findIndex(c => {
return c.mimeType === mimeType && (c.sdpFmtpLine === sdpFmtpLine || !sdpFmtpLine);
Expand Down
103 changes: 28 additions & 75 deletions webrtc/RTCRtpTransceiver-setCodecPreferences.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,13 @@
<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
* for details on how to enable support.
*/

test((t) => {
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 +23,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 Down Expand Up @@ -87,74 +50,64 @@
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.
let tried = false;
codecs.forEach(codec => {
if (codec.mimeType.toLowerCase() === 'video/vp8') {
transceiver.setCodecPreferences([codecs[0]]);
tried = true;
}
});
assert_true(tried, 'VP8 video codec was found and tried');
// and can be preferred.
const codec = codecs.find(c => c.mimeType === 'video/VP8');
assert_true(!!codec, 'VP8 video codec was found');
transceiver.setCodecPreferences([codec]);
}, `setCodecPreferences() with only VP8 should succeed`);

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.
let tried = false;
codecs.forEach(codec => {
if (codec.mimeType.toLowerCase() === 'video/h264') {
transceiver.setCodecPreferences([codecs[0]]);
tried = true;
}
});
assert_true(tried, 'H264 video codec was found and tried');
// and can be preferred.
const codec = codecs.find(c => c.mimeType === 'video/H264');
assert_true(!!codec, 'H264 video codec was found');
transceiver.setCodecPreferences([codec]);
}, `setCodecPreferences() with only H264 should succeed`);

async function getRTPMapLinesWithCodecAsFirst(firstCodec)
{
const capabilities = RTCRtpSender.getCapabilities('video').codecs;
capabilities.forEach((codec, idx) => {
const codecs = RTCRtpReceiver.getCapabilities('video').codecs;
codecs.forEach((codec, idx) => {
if (codec.mimeType === firstCodec) {
capabilities.splice(idx, 1);
capabilities.unshift(codec);
codecs.splice(idx, 1);
codecs.unshift(codec);
}
});

const pc = new RTCPeerConnection();
const transceiver = pc.addTransceiver('video');
transceiver.setCodecPreferences(capabilities);
transceiver.setCodecPreferences(codecs);
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.startsWith('a=rtpmap:'));
}

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 +143,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 +160,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 +171,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 +182,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 +193,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 @@ -257,7 +210,7 @@
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 +236,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

0 comments on commit 39ed5fa

Please sign in to comment.