Skip to content

Commit

Permalink
Bug 1728628 [wpt PR 30287] - Fix test picture generation and add test…
Browse files Browse the repository at this point in the history
…., a=testonly

Automatic update from web-platform-tests
Fix test picture generation and add test. (#30287)

This CL changes the test picture from a growing box to a small moving
box. It adds a test that the expected bandwidth target is achieved at
the expected resolution.

In a browser, 640x480 is not reached within 5 seconds. This is odd.

Bug: None.
Change-Id: I2d94f1c190c26cec6759ecc0f788feea8e52ed7c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3135833
Commit-Queue: Harald Alvestrand <hta@chromium.org>
Reviewed-by: Florent Castelli <orphis@chromium.org>
Cr-Commit-Position: refs/heads/main@{#917211}

Co-authored-by: Harald Alvestrand <hta@chromium.org>
--

wpt-commits: fb595c54c13e1dc40b9f8e68016079164114e8fd
wpt-pr: 30287
  • Loading branch information
chromium-wpt-export-bot authored and moz-wptsync-bot committed Sep 4, 2021
1 parent bd6305d commit 26b2df5
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="RTCPeerConnection-helper.js"></script>
<video id="videoin">
</video>
<video id="videoout">
</video>
<script>
'use strict';

Expand All @@ -18,4 +22,82 @@
await exchangeOfferAnswer(pc1, pc2);
await waitForState(transceiver.sender.transport, 'connected');
}, 'Setting up a connection using helpers and defaults should work');

function bandwidth(stats1, stats2) {
const transport1 = [...stats1.values()].filter(({type}) => type === 'transport')[0];
const transport2 = [...stats2.values()].filter(({type}) => type === 'transport')[0];
const bytes = transport2.bytesReceived - transport1.bytesReceived;
// Timestamps are in milliseconds.
// Multiply by 1000 to get bytes per second, multiply by 8 to get bits/s.
const bandwidth = 1000 * 8 * bytes /
(transport2.timestamp - transport1.timestamp);
return bandwidth;
}

// Returns tuple of { bandwidth, fps, x-res, y-res }
async function measureStuff(t, pc, intervalMs) {
const stats1 = await pc.getStats();
await new Promise(r => t.step_timeout(r, intervalMs));
const stats2 = await pc.getStats();
// RTCInboundStreamStats
const inboundRtp1List = [...stats1.values()].filter(({type}) => type === 'inbound-rtp');
const inboundRtp2List = [...stats2.values()].filter(({type}) => type === 'inbound-rtp');
const inboundRtp1 = inboundRtp1List[0];
const inboundRtp2 = inboundRtp2List[0];
const fps = 1000 * (inboundRtp2.framesReceived - inboundRtp1.framesReceived) /
(inboundRtp2.timestamp - inboundRtp1.timestamp);
const result = {
bandwidth: bandwidth(stats1, stats2),
fps: fps,
width: inboundRtp2.frameWidth,
height: inboundRtp2.frameHeight
};
// Unbreak for debugging.
// con sole.log('Measure: ', performance.now(), " ", JSON.stringify(result));
return result;
}

// Wait for a certain condition to be true on the traffic measures
// on the PC. Will typically be conditions on resolution, framerate
// or bandwidth.
async function waitForCondition(t, pc, condition, maxWait, stepName) {
let counter = 1;
let measure = await measureStuff(t, pc, 1000);
while (counter < maxWait && !condition(measure)) {
measure = await measureStuff(t, pc, 1000);
counter += 1;
}
assert_true(condition(measure),
`failure in ${stepName}, measure is ${JSON.stringify(measure)}`);
return condition(measure);
}

promise_test(async t => {
const pc1 = new RTCPeerConnection();
const pc2 = new RTCPeerConnection();
t.add_cleanup(() => pc1.close());
t.add_cleanup(() => pc2.close());
const stream = await getNoiseStream({video: true});
const videoInDisplay = document.getElementById('videoin');
videoInDisplay.srcObject = stream;
t.add_cleanup(() => stream.getTracks().forEach(track => track.stop()));
const sender = pc1.addTrack(stream.getTracks()[0]);
pc2.ontrack = (e) => {
const videoOutDisplay = document.getElementById('videoout');
const stream = new MediaStream([e.track]);
videoOutDisplay.srcObject = stream;
}
exchangeIceCandidates(pc1, pc2);
await exchangeOfferAnswer(pc1, pc2);
await waitForState(sender.transport, 'connected');

// Note - we expected 640x480 here, because that's what's generated.
// This works in blink_tests, but not in a browser in reasonable time.
assert_true(await waitForCondition(t, pc2, (measure) => {
return (measure.bandwidth > 40000 &&
measure.width >= 480 &&
measure.fps > 9);
}, 15, 'video track size - may include keyframe'));
}, 'A test video track transmits at least 40 Kbits/sec of data at 480x360 size');

</script>
4 changes: 2 additions & 2 deletions testing/web-platform/tests/webrtc/RTCPeerConnection-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,10 +412,10 @@ const trackFactories = {
ctx.fillStyle = `rgb(${contrast%255}, ${contrast*contrast%255}, ${contrast%255})`;
const xpos = count % (width - 20);
const ypos = count % (height - 20);
ctx.fillRect(xpos, ypos, xpos + 20, ypos + 20);
ctx.fillRect(xpos, ypos, 20, 20);
const xpos2 = (count + width / 2) % (width - 20);
const ypos2 = (count + height / 2) % (height - 20);
ctx.fillRect(xpos2, ypos2, xpos2 + 20, ypos2 + 20);
ctx.fillRect(xpos2, ypos2, 20, 20);
// If signal is set (0-255), add a constant-color box of that luminance to
// the video frame at coordinates 20 to 60 in both X and Y direction.
// (big enough to avoid color bleed from surrounding video in some codecs,
Expand Down

0 comments on commit 26b2df5

Please sign in to comment.