blob: d7fb0888468765f03e52dbf128e7c3766b636142 (
plain)
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
|
<!DOCTYPE html>
<html>
<head>
<title>RTCPeerConnection Insertable Streams - Video Frames</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src=/resources/testdriver.js></script>
<script src=/resources/testdriver-vendor.js></script>
<script src='../mediacapture-streams/permission-helper.js'></script>
<script src="../webrtc/RTCPeerConnection-helper.js"></script>
<script src="./RTCPeerConnection-insertable-streams.js"></script>
</head>
<body>
<script>
promise_test(async t => {
const caller = new RTCPeerConnection({encodedInsertableStreams:true});
t.add_cleanup(() => caller.close());
const callee = new RTCPeerConnection({encodedInsertableStreams:true});
t.add_cleanup(() => callee.close());
await setMediaPermission("granted", ["camera"]);
const stream = await navigator.mediaDevices.getUserMedia({video:true});
const track = stream.getTracks()[0];
t.add_cleanup(() => track.stop());
const sender = caller.addTrack(track)
const senderStreams = sender.createEncodedStreams();
const senderReader = senderStreams.readable.getReader();
const senderWriter = senderStreams.writable.getWriter();
const numFramesToSend = 20;
const ontrackPromise = new Promise((resolve, reject) => {
callee.ontrack = async e => {
const receiverStreams = e.receiver.createEncodedStreams();
const receiverReader = receiverStreams.readable.getReader();
let numReceivedKeyFrames = 0;
let numReceivedDeltaFrames = 0;
for (let i = 0; i < numFramesToSend; i++) {
const result = await receiverReader.read();
if (result.value.type == 'key')
numReceivedKeyFrames++;
else if (result.value.type == 'delta')
numReceivedDeltaFrames++;
if (numReceivedKeyFrames > 0 && numReceivedDeltaFrames > 0)
resolve();
else if (numReceivedKeyFrames + numReceivedDeltaFrames >= numFramesToSend)
reject();
}
}
});
exchangeIceCandidates(caller, callee);
await exchangeOfferAnswer(caller, callee);
let numSentKeyFrames = 0;
let numSentDeltaFrames = 0;
// Pass frames as they come from the encoder.
for (let i = 0; i < numFramesToSend; i++) {
const result = await senderReader.read();
verifyNonstandardAdditionalDataIfPresent(result.value);
if (result.value.type == 'key') {
numSentKeyFrames++;
} else {
numSentDeltaFrames++;
}
senderWriter.write(result.value);
}
assert_greater_than(numSentKeyFrames, 0);
assert_greater_than(numSentDeltaFrames, 0);
return ontrackPromise;
}, 'Key and Delta frames are sent and received');
</script>
</body>
</html>
|