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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543
|
<!doctype html>
<meta charset=utf-8>
<title>RTCRtpParameters encodings</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="dictionary-helper.js"></script>
<script src="RTCRtpParameters-helper.js"></script>
<script>
'use strict';
// Test is based on the following editor draft:
// https://w3c.github.io/webrtc-pc/archives/20170605/webrtc.html
// The following helper functions are called from RTCRtpParameters-helper.js:
// validateSenderRtpParameters
/*
5.1. RTCPeerConnection Interface Extensions
partial interface RTCPeerConnection {
RTCRtpTransceiver addTransceiver((MediaStreamTrack or DOMString) trackOrKind,
optional RTCRtpTransceiverInit init);
...
};
dictionary RTCRtpTransceiverInit {
RTCRtpTransceiverDirection direction = "sendrecv";
sequence<MediaStream> streams;
sequence<RTCRtpEncodingParameters> sendEncodings;
};
5.2. RTCRtpSender Interface
interface RTCRtpSender {
Promise<void> setParameters(optional RTCRtpParameters parameters);
RTCRtpParameters getParameters();
};
dictionary RTCRtpParameters {
DOMString transactionId;
sequence<RTCRtpEncodingParameters> encodings;
sequence<RTCRtpHeaderExtensionParameters> headerExtensions;
RTCRtcpParameters rtcp;
sequence<RTCRtpCodecParameters> codecs;
};
dictionary RTCRtpEncodingParameters {
boolean active;
unsigned long maxBitrate;
[readonly]
DOMString rid;
double scaleResolutionDownBy;
};
getParameters
- encodings is set to the value of the [[send encodings]] internal slot.
*/
promise_test(async t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
const transceiver = pc.addTransceiver('video');
const param = transceiver.sender.getParameters();
assert_equals(param.encodings.length, 1);
// Do not call this in every test; it does not make sense to disable all of
// the tests below for an implementation that is missing support for
// fields that are not related to the test.
validateSenderRtpParameters(param);
}, `getParameters should return RTCRtpEncodingParameters with all required fields`);
/*
5.1. addTransceiver
7. Create an RTCRtpSender with track, streams and sendEncodings and let sender
be the result.
5.2. create an RTCRtpSender
5. Let sender have a [[send encodings]] internal slot, representing a list
of RTCRtpEncodingParameters dictionaries.
6. If sendEncodings is given as input to this algorithm, and is non-empty,
set the [[send encodings]] slot to sendEncodings.
Otherwise, set it to a list containing a single RTCRtpEncodingParameters
with active set to true.
*/
promise_test(async t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
const transceiver = pc.addTransceiver('audio');
const param = transceiver.sender.getParameters();
const { encodings } = param;
assert_equals(encodings.length, 1);
const encoding = param.encodings[0];
assert_equals(encoding.active, true);
assert_not_own_property(encoding, "maxBitrate");
assert_not_own_property(encoding, "rid");
assert_not_own_property(encoding, "scaleResolutionDownBy");
// We do not check props from extension specifications here; those checks
// need to go in a test-case for that extension specification.
}, 'addTransceiver(audio) with undefined sendEncodings should have default encoding parameter with active set to true');
promise_test(async t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
const transceiver = pc.addTransceiver('video');
const param = transceiver.sender.getParameters();
const { encodings } = param;
assert_equals(encodings.length, 1);
const encoding = param.encodings[0];
assert_equals(encoding.active, true);
// spec says to return an encoding without a scaleResolutionDownBy value
// when addTransceiver does not pass any encodings, however spec also says
// to throw if setParameters is missing a scaleResolutionDownBy. One of
// these two requirements needs to be removed, but it is unclear right now
// which will be removed. For now, allow scaleResolutionDownBy, but don't
// require it.
// https://github.com/w3c/webrtc-pc/issues/2730
assert_not_own_property(encoding, "maxBitrate");
assert_not_own_property(encoding, "rid");
assert_equals(encoding.scaleResolutionDownBy, 1.0);
// We do not check props from extension specifications here; those checks
// need to go in a test-case for that extension specification.
}, 'addTransceiver(video) with undefined sendEncodings should have default encoding parameter with active set to true and scaleResolutionDownBy set to 1');
promise_test(async t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
const transceiver = pc.addTransceiver('audio', { sendEncodings: [] });
const param = transceiver.sender.getParameters();
const { encodings } = param;
assert_equals(encodings.length, 1);
const encoding = param.encodings[0];
assert_equals(encoding.active, true);
assert_not_own_property(encoding, "maxBitrate");
assert_not_own_property(encoding, "rid");
assert_not_own_property(encoding, "scaleResolutionDownBy");
// We do not check props from extension specifications here; those checks
// need to go in a test-case for that extension specification.
}, 'addTransceiver(audio) with empty list sendEncodings should have default encoding parameter with active set to true');
promise_test(async t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
const transceiver = pc.addTransceiver('video', { sendEncodings: [] });
const param = transceiver.sender.getParameters();
const { encodings } = param;
assert_equals(encodings.length, 1);
const encoding = param.encodings[0];
assert_equals(encoding.active, true);
assert_not_own_property(encoding, "maxBitrate");
assert_not_own_property(encoding, "rid");
assert_equals(encoding.scaleResolutionDownBy, 1.0);
// We do not check props from extension specifications here; those checks
// need to go in a test-case for that extension specification.
}, 'addTransceiver(video) with empty list sendEncodings should have default encoding parameter with active set to true and scaleResolutionDownBy set to 1');
promise_test(async t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
const transceiver = pc.addTransceiver('video', {sendEncodings: [{rid: "foo"}, {rid: "bar", scaleResolutionDownBy: 3.0}]});
const param = transceiver.sender.getParameters();
const { encodings } = param;
assert_equals(encodings.length, 2);
assert_equals(encodings[0].scaleResolutionDownBy, 1.0);
assert_equals(encodings[1].scaleResolutionDownBy, 3.0);
}, `addTransceiver(video) should auto-set scaleResolutionDownBy to 1 when some encodings have it, but not all`);
promise_test(async t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
const transceiver = pc.addTransceiver('video', {sendEncodings: [{rid: "foo"}, {rid: "bar"}]});
const param = transceiver.sender.getParameters();
const { encodings } = param;
assert_equals(encodings.length, 2);
assert_equals(encodings[0].scaleResolutionDownBy, 2.0);
assert_equals(encodings[1].scaleResolutionDownBy, 1.0);
}, `addTransceiver should auto-set scaleResolutionDownBy to powers of 2 (descending) when absent`);
promise_test(async t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
const sendEncodings = [];
for (let i = 0; i < 1000; i++) {
sendEncodings.push({rid: i});
}
const transceiver = pc.addTransceiver('video', {sendEncodings});
const param = transceiver.sender.getParameters();
const { encodings } = param;
assert_less_than(encodings.length, 1000, `1000 encodings is clearly too many`);
}, `addTransceiver with a ridiculous number of encodings should truncate the list`);
promise_test(async t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
const transceiver = pc.addTransceiver('audio', {sendEncodings: [{rid: "foo"}, {rid: "bar"}]});
const param = transceiver.sender.getParameters();
const { encodings } = param;
assert_equals(encodings.length, 1);
assert_not_own_property(encodings[0], "maxBitrate");
assert_not_own_property(encodings[0], "rid");
assert_not_own_property(encodings[0], "scaleResolutionDownBy");
// We do not check props from extension specifications here; those checks
// need to go in a test-case for that extension specification.
}, `addTransceiver(audio) with multiple encodings should result in one encoding with no properties other than active`);
promise_test(async t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
const {sender} = pc.addTransceiver('audio', {sendEncodings: [{rid: "foo", scaleResolutionDownBy: 2.0}]});
const {encodings} = sender.getParameters();
assert_equals(encodings.length, 1);
assert_not_own_property(encodings[0], "scaleResolutionDownBy");
}, `addTransceiver(audio) should remove valid scaleResolutionDownBy`);
promise_test(async t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
const {sender} = pc.addTransceiver('audio', {sendEncodings: [{rid: "foo", scaleResolutionDownBy: -1.0}]});
const {encodings} = sender.getParameters();
assert_equals(encodings.length, 1);
assert_not_own_property(encodings[0], "scaleResolutionDownBy");
}, `addTransceiver(audio) should remove invalid scaleResolutionDownBy`);
promise_test(async t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
const {sender} = pc.addTransceiver('audio');
let params = sender.getParameters();
assert_equals(params.encodings.length, 1);
params.encodings[0].scaleResolutionDownBy = 2;
await sender.setParameters(params);
const {encodings} = sender.getParameters();
assert_equals(encodings.length, 1);
assert_not_own_property(encodings[0], "scaleResolutionDownBy");
}, `setParameters with scaleResolutionDownBy on an audio sender should succeed, but remove the scaleResolutionDownBy`);
promise_test(async t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
const {sender} = pc.addTransceiver('audio');
let params = sender.getParameters();
assert_equals(params.encodings.length, 1);
params.encodings[0].scaleResolutionDownBy = -1;
await sender.setParameters(params);
const {encodings} = sender.getParameters();
assert_equals(encodings.length, 1);
assert_not_own_property(encodings[0], "scaleResolutionDownBy");
}, `setParameters with an invalid scaleResolutionDownBy on an audio sender should succeed, but remove the scaleResolutionDownBy`);
promise_test(async t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
assert_throws_js(TypeError, () => pc.addTransceiver('video', { sendEncodings: [{rid: "foo"}, {rid: "foo"}] }));
}, 'addTransceiver with duplicate rid and multiple encodings throws TypeError');
promise_test(async t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
assert_throws_js(TypeError, () => pc.addTransceiver('video', { sendEncodings: [{rid: "foo"}, {}] }));
}, 'addTransceiver with missing rid and multiple encodings throws TypeError');
promise_test(async t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
assert_throws_js(TypeError, () => pc.addTransceiver('video', { sendEncodings: [{rid: ""}] }));
}, 'addTransceiver with empty rid throws TypeError');
promise_test(async t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
assert_throws_js(TypeError, () => pc.addTransceiver('video', { sendEncodings: [{rid: "!?"}] }));
assert_throws_js(TypeError, () => pc.addTransceiver('video', { sendEncodings: [{rid: "(╯°□°)╯︵ ┻━┻"}] }));
// RFC 8851 says '-' and '_' are allowed, but RFC 8852 says they are not.
// RFC 8852 needs to be adhered to, otherwise we can't put the rid in RTP
// https://github.com/w3c/webrtc-pc/issues/2732
// https://www.rfc-editor.org/errata/eid7132
assert_throws_js(TypeError, () => pc.addTransceiver('video', { sendEncodings: [{rid: "foo-bar"}] }));
assert_throws_js(TypeError, () => pc.addTransceiver('video', { sendEncodings: [{rid: "foo_bar"}] }));
}, 'addTransceiver with invalid rid characters throws TypeError');
promise_test(async t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
// https://github.com/w3c/webrtc-pc/issues/2732
assert_throws_js(TypeError, () => pc.addTransceiver('video', { sendEncodings: [{rid: 'a'.repeat(256)}] }));
}, 'addTransceiver with rid longer than 255 characters throws TypeError');
promise_test(async t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
assert_throws_js(RangeError, () => pc.addTransceiver('video', { sendEncodings: [{scaleResolutionDownBy: -1}] }));
assert_throws_js(RangeError, () => pc.addTransceiver('video', { sendEncodings: [{scaleResolutionDownBy: 0}] }));
assert_throws_js(RangeError, () => pc.addTransceiver('video', { sendEncodings: [{scaleResolutionDownBy: 0.5}] }));
}, `addTransceiver with scaleResolutionDownBy < 1 throws RangeError`);
/*
5.2. create an RTCRtpSender
To create an RTCRtpSender with a MediaStreamTrack , track, a list of MediaStream
objects, streams, and optionally a list of RTCRtpEncodingParameters objects,
sendEncodings, run the following steps:
5. Let sender have a [[send encodings]] internal slot, representing a list
of RTCRtpEncodingParameters dictionaries.
6. If sendEncodings is given as input to this algorithm, and is non-empty,
set the [[send encodings]] slot to sendEncodings.
5.2. getParameters
- encodings is set to the value of the [[send encodings]] internal slot.
*/
promise_test(async t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
const { sender } = pc.addTransceiver('video', {
sendEncodings: [{
active: false,
maxBitrate: 8,
rid: 'foo'
}]
});
const param = sender.getParameters();
const encoding = param.encodings[0];
assert_equals(encoding.active, false);
assert_equals(encoding.maxBitrate, 8);
assert_not_own_property(encoding, "rid", "rid should be removed with a single encoding");
}, `sender.getParameters() should return sendEncodings set by addTransceiver()`);
/*
5.2. setParameters
3. Let N be the number of RTCRtpEncodingParameters stored in sender's internal
[[send encodings]] slot.
7. If parameters.encodings.length is different from N, or if any parameter
in the parameters argument, marked as a Read-only parameter, has a value
that is different from the corresponding parameter value returned from
sender.getParameters(), abort these steps and return a promise rejected
with a newly created InvalidModificationError. Note that this also applies
to transactionId.
*/
promise_test(async t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
const { sender } = pc.addTransceiver('video');
const param = sender.getParameters();
const { encodings } = param;
assert_equals(encodings.length, 1);
// While {} is valid RTCRtpEncodingParameters because all fields are
// optional, it is still invalid to be missing a rid when there are multiple
// encodings. Only trigger one kind of error here.
encodings.push({ rid: "foo" });
assert_equals(param.encodings.length, 2);
return promise_rejects_dom(t, 'InvalidModificationError',
sender.setParameters(param));
}, `sender.setParameters() with added encodings should reject with InvalidModificationError`);
promise_test(async t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
const { sender } = pc.addTransceiver('video', {sendEncodings: [{rid: "foo"}, {rid: "bar"}]});
const param = sender.getParameters();
const { encodings } = param;
assert_equals(encodings.length, 2);
encodings.pop();
assert_equals(param.encodings.length, 1);
return promise_rejects_dom(t, 'InvalidModificationError',
sender.setParameters(param));
}, `sender.setParameters() with removed encodings should reject with InvalidModificationError`);
promise_test(async t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
const { sender } = pc.addTransceiver('video', {sendEncodings: [{rid: "foo"}, {rid: "bar"}]});
const param = sender.getParameters();
const { encodings } = param;
assert_equals(encodings.length, 2);
encodings.push(encodings.shift());
assert_equals(param.encodings.length, 2);
return promise_rejects_dom(t, 'InvalidModificationError',
sender.setParameters(param));
}, `sender.setParameters() with reordered encodings should reject with InvalidModificationError`);
promise_test(async t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
const { sender } = pc.addTransceiver('video');
const param = sender.getParameters();
delete param.encodings;
return promise_rejects_js(t, TypeError,
sender.setParameters(param));
}, `sender.setParameters() with encodings unset should reject with TypeError`);
promise_test(async t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
const { sender } = pc.addTransceiver('video');
const param = sender.getParameters();
param.encodings = [];
return promise_rejects_dom(t, 'InvalidModificationError',
sender.setParameters(param));
}, `sender.setParameters() with empty encodings should reject with InvalidModificationError (video)`);
promise_test(async t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
const { sender } = pc.addTransceiver('audio');
const param = sender.getParameters();
param.encodings = [];
return promise_rejects_dom(t, 'InvalidModificationError',
sender.setParameters(param));
}, `sender.setParameters() with empty encodings should reject with InvalidModificationError (audio)`);
promise_test(async t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
const { sender } = pc.addTransceiver('video', {
sendEncodings: [{ rid: 'foo' }, { rid: 'baz' }],
});
const param = sender.getParameters();
const encoding = param.encodings[0];
assert_equals(encoding.rid, 'foo');
encoding.rid = 'bar';
return promise_rejects_dom(t, 'InvalidModificationError',
sender.setParameters(param));
}, `setParameters() with modified encoding.rid field should reject with InvalidModificationError`);
/*
5.2. setParameters
8. If the scaleResolutionDownBy parameter in the parameters argument has a
value less than 1.0, abort these steps and return a promise rejected with
a newly created RangeError.
*/
promise_test(async t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
const { sender } = pc.addTransceiver('video');
const param = sender.getParameters();
const encoding = param.encodings[0];
encoding.scaleResolutionDownBy = 0.5;
await promise_rejects_js(t, RangeError, sender.setParameters(param));
encoding.scaleResolutionDownBy = 0;
await promise_rejects_js(t, RangeError, sender.setParameters(param));
encoding.scaleResolutionDownBy = -1;
await promise_rejects_js(t, RangeError, sender.setParameters(param));
}, `setParameters() with encoding.scaleResolutionDownBy field set to less than 1.0 should reject with RangeError`);
promise_test(async t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
const { sender } = pc.addTransceiver('video');
let param = sender.getParameters();
const encoding = param.encodings[0];
delete encoding.scaleResolutionDownBy;
await sender.setParameters(param);
param = sender.getParameters();
assert_equals(param.encodings[0].scaleResolutionDownBy, 1.0);
}, `setParameters() with missing encoding.scaleResolutionDownBy field should succeed, and set the value back to 1`);
promise_test(async t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
const { sender } = pc.addTransceiver('video');
const param = sender.getParameters();
const encoding = param.encodings[0];
encoding.scaleResolutionDownBy = 1.5;
return sender.setParameters(param)
.then(() => {
const param = sender.getParameters();
const encoding = param.encodings[0];
assert_approx_equals(encoding.scaleResolutionDownBy, 1.5, 0.01);
});
}, `setParameters() with encoding.scaleResolutionDownBy field set to greater than 1.0 should succeed`);
test_modified_encoding('video', 'active', false, true,
'setParameters() with encoding.active false->true should succeed (video)');
test_modified_encoding('video', 'active', true, false,
'setParameters() with encoding.active true->false should succeed (video)');
test_modified_encoding('video', 'maxBitrate', 10000, 20000,
'setParameters() with modified encoding.maxBitrate should succeed (video)');
test_modified_encoding('audio', 'active', false, true,
'setParameters() with encoding.active false->true should succeed (audio)');
test_modified_encoding('audio', 'active', true, false,
'setParameters() with encoding.active true->false should succeed (audio)');
test_modified_encoding('audio', 'maxBitrate', 10000, 20000,
'setParameters() with modified encoding.maxBitrate should succeed (audio)');
test_modified_encoding('video', 'scaleResolutionDownBy', 2, 4,
'setParameters() with modified encoding.scaleResolutionDownBy should succeed');
</script>
|