Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add wpt to use stats to measure jitterBufferTarget.
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
1 parent
01f72bd
commit a306eeb
Showing
1 changed file
with
91 additions
and
0 deletions.
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
webrtc-extensions/RTCRtpReceiver-jitterBufferTarget-stats.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |