-
Notifications
You must be signed in to change notification settings - Fork 3k
/
RTCRtpReceiver-jitterBufferTarget-stats.html
91 lines (83 loc) · 3.86 KB
/
RTCRtpReceiver-jitterBufferTarget-stats.html
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
<!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>