Skip to content

Commit

Permalink
Add wpt to use stats to measure jitterBufferTarget.
Browse files Browse the repository at this point in the history
Differential Revision: https://phabricator.services.mozilla.com/D178484

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1592988
gecko-commit: 38320c197609eae03222a0bf0678b364576c8c9f
gecko-reviewers: jib
  • Loading branch information
Drekabi authored and moz-wptsync-bot committed May 23, 2023
1 parent 01f72bd commit a306eeb
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions webrtc-extensions/RTCRtpReceiver-jitterBufferTarget-stats.html
@@ -0,0 +1,91 @@
<!DOCTYPE html>
<meta charset="utf-8">
<meta name="timeout" content="long">
<title>Tests RTCRtpReceiver-jitterBufferTarget verified with stats</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/webrtc/RTCPeerConnection-helper.js"></script>
<body>
<script>
'use strict'

function async_promise_test(func, name, properties) {
async_test(t => {
Promise.resolve(func(t))
.catch(t.step_func(e => { throw e; }))
.then(() => t.done());
}, name, properties);
}

async_promise_test(t => applyJitterBufferTarget(t, "video", 250),
"measure raising video jitterBufferTarget to 250");
async_promise_test(t => applyJitterBufferTarget(t, "audio", 250),
"measure raising audio jitterBufferTarget to 250");
async_promise_test(t => applyJitterBufferTarget(t, "video", 500),
"measure raising video jitterBufferTarget to 500");
async_promise_test(t => applyJitterBufferTarget(t, "audio", 500),
"measure raising audio jitterBufferTarget to 500");
async_promise_test(t => applyJitterBufferTarget(t, "video", 250, 50),
"measure lowering video jitterBufferTarget to 50");
async_promise_test(t => applyJitterBufferTarget(t, "audio", 250, 50),
"measure lowering audio jitterBufferTarget to 50");
async_promise_test(t => applyJitterBufferTarget(t, "video", 500, 150),
"measure lowering video jitterBufferTarget to 150");
async_promise_test(t => applyJitterBufferTarget(t, "audio", 500, 150),
"measure lowering audio jitterBufferTarget to 150");

async function applyJitterBufferTarget(t, kind, target, targetToLower) {
const caller = new RTCPeerConnection();
t.add_cleanup(() => caller.close());
const callee = new RTCPeerConnection();
t.add_cleanup(() => callee.close());

const stream = await getNoiseStream({[kind]:true});
t.add_cleanup(() => stream.getTracks().forEach(track => track.stop()));
for (const track of stream.getTracks()) {
caller.addTrack(track, stream);
}
exchangeIceCandidates(caller, callee);
await exchangeOfferAnswer(caller, callee);
const receiver = callee.getReceivers().find(({track}) => track.kind == kind);
t.step(() => assert_equals(receiver.jitterBufferTarget, null,
`jitterBufferTarget supported for ${kind}`));
receiver.jitterBufferTarget = target;
t.step(() => assert_equals(receiver.jitterBufferTarget, target,
`jitterBufferTarget increase target for ${kind}`));
const delay = await measureDelayFromStats(t, receiver, callee, target, kind);

if (targetToLower) {
t.step(() => assert_less_than(targetToLower, delay, "targetToLower represents a decrease"));
receiver.jitterBufferTarget = targetToLower;
t.step(() => assert_equals(receiver.jitterBufferTarget, targetToLower,
`jitterBufferTarget decrease target for ${kind}`));
await measureDelayFromStats(t, receiver, callee, targetToLower, kind);
}
}

async function measureDelayFromStats(t, receiver, callee, target, kind) {
const lowerBound = target * 0.7;
const upperBound = target * 1.3;
let delay, oldInboundStats;

for (let statChecks = 0; statChecks < 40; statChecks++) {
await new Promise(r => t.step_timeout(r, 1000));
const statsReport = await callee.getStats();
const inboundStats = [...statsReport.values()].find(({type}) => type == "inbound-rtp");

if (oldInboundStats) {
delay = ((inboundStats.jitterBufferDelay - oldInboundStats.jitterBufferDelay) /
(inboundStats.jitterBufferEmittedCount - oldInboundStats.jitterBufferEmittedCount) * 1000);
if (delay > lowerBound && delay < upperBound) {
break;
}
}
oldInboundStats = inboundStats;
}
t.step(() => assert_between_inclusive(delay , lowerBound, upperBound,
`${kind} delay is within bounds`));
return delay;
}
</script>
</body>

0 comments on commit a306eeb

Please sign in to comment.