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
|
<!doctype html>
<meta charset=utf-8>
<meta name="timeout" content="long">
<title>RTCPeerConnection-remote-track-currentTime.https.html</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="RTCPeerConnection-helper.js"></script>
<script>
'use strict';
/*
* This test is checking the below spec text for MediaStreamTracks received
* through an RTCPeerConnection.
*
* ยง 6. MediaStreams in Media Elements
*
* A MediaStream (...) represents a simple, potentially infinite, linear media
* timeline. The timeline starts at 0 and increments linearly in real time as
* long as the media element is potentially playing. The timeline does not
* increment when the playout of the MediaStream is paused.
*/
async function setupPeerConnectionAndWaitForTrack(t, kind) {
const pc1 = createPeerConnectionWithCleanup(t);
pc1.addTrack(... await createTrackAndStreamWithCleanup(t, "video"));
const pc2 = createPeerConnectionWithCleanup(t);
exchangeIceCandidates(pc1, pc2);
const haveTrack = waitUntilEvent(pc2, "track");
await exchangeOfferAnswer(pc1, pc2);
const {track} = await haveTrack;
return {pc1, pc2, track};
}
async function setupMediaElementAndCheckInitialCurrentTime(t, track) {
const elem = document.createElement(track.kind);
elem.srcObject = new MediaStream([track]);
assert_equals(elem.currentTime, 0, "currentTime starts at 0");
elem.play();
await new Promise(r => elem.ontimeupdate = r);
assert_between_exclusive(elem.currentTime, 0, 0.5,
"currentTime starts at 0 and has progressed at first timeupdate"
);
assert_equals(elem.readyState, elem.HAVE_ENOUGH_DATA,
"Media element has enough data once currentTime is progressing"
);
return elem;
}
async function checkCurrentTimeProgressing(t, elem) {
const currentTime1 = elem.currentTime;
// Note that when `currentTime1` was updated by the UA, it dispatched a task
// to fire a "timeupdate" event (per the "time marches on" algorithm in the
// spec). This event may not have fired yet, which is why we must wait for two
// such events.
try {
await Promise.race([
(async () =>
{
await waitUntilEvent(elem, "timeupdate");
await waitUntilEvent(elem, "timeupdate");
}
)(),
new Promise((res, rej) => t.step_timeout(rej, 3000)),
]);
} catch(e) {
assert_unreached("Timed out waiting for timeupdate");
}
assert_greater_than(elem.currentTime, currentTime1);
}
async function setSenderActive(t, sender, active) {
const parameters = sender.getParameters();
parameters.encodings[0].active = active;
await sender.setParameters(parameters);
// Wait a bit longer to be certain the parameter changes have propagated to
// the receiver.
await new Promise(r => t.step_timeout(r, 100));
}
promise_test(async t => {
const {track} = await setupPeerConnectionAndWaitForTrack(t, "audio");
const elem = await setupMediaElementAndCheckInitialCurrentTime(t, track);
await checkCurrentTimeProgressing(t, elem);
}, 'currentTime advances for receive audio track of active sender');
promise_test(async t => {
const {track} = await setupPeerConnectionAndWaitForTrack(t, "video");
const elem = await setupMediaElementAndCheckInitialCurrentTime(t, track);
await checkCurrentTimeProgressing(t, elem);
}, 'currentTime advances for receive video track of active sender');
promise_test(async t => {
const {pc1, track} = await setupPeerConnectionAndWaitForTrack(t, "audio");
const elem = await setupMediaElementAndCheckInitialCurrentTime(t, track);
await setSenderActive(t, pc1.getSenders()[0], false);
await checkCurrentTimeProgressing(t, elem);
}, 'currentTime advances for receive audio track of inactive sender');
promise_test(async t => {
const {pc1, track} = await setupPeerConnectionAndWaitForTrack(t, "video");
const elem = await setupMediaElementAndCheckInitialCurrentTime(t, track);
await setSenderActive(t, pc1.getSenders()[0], false);
await checkCurrentTimeProgressing(t, elem);
}, 'currentTime advances for receive video track of inactive sender');
</script>
|