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
|
<!DOCTYPE HTML>
<html>
<head>
<script type="application/javascript" src="pc.js"></script>
</head>
<body>
<pre id="test">
<script type="application/javascript">
createHTML({
bug: "1253499",
title: "Live-updating scaleResolutionDownBy"
});
async function checkForH264Support() {
const pc = new RTCPeerConnection();
const offer = await pc.createOffer({offerToReceiveVideo: true});
return offer.sdp.match(/a=rtpmap:[1-9][0-9]* H264/);
}
let sender, localElem, remoteElem;
let originalWidth, originalHeight;
let resolutionAlignment = 1;
async function checkScaleDownBy(scale) {
const parameters = sender.getParameters();
parameters.encodings[0].scaleResolutionDownBy = scale;
await sender.setParameters(parameters);
await haveEvent(remoteElem, "resize", wait(5000, new Error("Timeout")));
// Find the expected resolution. Internally we floor the exact scaling, then
// shrink each dimension to the alignment requested by the encoder.
let expectedWidth =
originalWidth / scale - (originalWidth / scale % resolutionAlignment);
let expectedHeight =
originalHeight / scale - (originalHeight / scale % resolutionAlignment);
is(remoteElem.videoWidth, expectedWidth,
`Width should have scaled down by ${scale}`);
is(remoteElem.videoHeight, expectedHeight,
`Height should have scaled down by ${scale}`);
}
runNetworkTest(async function (options) {
await pushPrefs(['media.peerconnection.video.lock_scaling', true]);
// [TODO] re-enable HW decoder after bug 1526207 is fixed.
if (navigator.userAgent.includes("Android")) {
if (await checkForH264Support()) {
// Android only has h264 in hw, so now we know it will use vp8 in hw too.
resolutionAlignment = 16;
}
await pushPrefs(["media.navigator.mediadatadecoder_vpx_enabled", false],
["media.webrtc.hw.h264.enabled", false]);
}
let test = new PeerConnectionTest(options);
test.setMediaConstraints([{video: true}], []);
test.chain.append([
function CHECK_PRECONDITIONS() {
is(test.pcLocal._pc.getSenders().length, 1,
"Should have 1 local sender");
is(test.pcLocal.localMediaElements.length, 1,
"Should have 1 local sending media element");
is(test.pcRemote.remoteMediaElements.length, 1,
"Should have 1 remote media element");
sender = test.pcLocal._pc.getSenders()[0];
localElem = test.pcLocal.localMediaElements[0];
remoteElem = test.pcRemote.remoteMediaElements[0];
remoteElem.addEventListener("resize", () =>
info(`Video resized to ${remoteElem.videoWidth}x${remoteElem.videoHeight}`));
originalWidth = localElem.videoWidth;
originalHeight = localElem.videoHeight;
info(`Original width is ${originalWidth}`);
},
function PC_LOCAL_SCALEDOWNBY_2() {
return checkScaleDownBy(2);
},
function PC_LOCAL_SCALEDOWNBY_4() {
return checkScaleDownBy(4);
},
function PC_LOCAL_SCALEDOWNBY_15() {
return checkScaleDownBy(15);
},
function PC_LOCAL_SCALEDOWNBY_8() {
return checkScaleDownBy(8);
},
function PC_LOCAL_SCALEDOWNBY_1() {
return checkScaleDownBy(1);
},
]);
await test.run();
});
</script>
</pre>
</body>
</html>
|