summaryrefslogtreecommitdiffstats
path: root/dom/media/webrtc/tests/mochitests/test_peerConnection_renderAfterRenegotiation.html
blob: c8091d7a9ec3237a6b3bd915508f7350b5345a73 (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
81
82
83
84
85
86
87
88
89
<!DOCTYPE HTML>
<html>
<head>
  <script type="application/javascript" src="pc.js"></script>
  <script type="application/javascript" src="/tests/dom/canvas/test/captureStream_common.js"></script>
</head>
<body>
<pre id="test">
<script type="application/javascript">
  createHTML({
    bug: "1273652",
    title: "Video receiver still renders after renegotiation",
    visible: true
  });

  var pc1 = new RTCPeerConnection();
  var pc2 = new RTCPeerConnection();

  var add = (pc, can, failed) => can && pc.addIceCandidate(can).catch(failed);
  pc1.onicecandidate = e => add(pc2, e.candidate, generateErrorCallback());
  pc2.onicecandidate = e => add(pc1, e.candidate, generateErrorCallback());

  var v1, v2;
  var delivered = new Promise(resolve => pc2.ontrack = e => {
    // Test RTCTrackEvent here.
    ok(e.streams.length, "has streams");
    ok(e.streams[0].getTrackById(e.track.id), "has track");
    ok(pc2.getReceivers().some(receiver => receiver == e.receiver), "has receiver");
    if (e.streams[0].getTracks().length == 1) {
      // Test RTCTrackEvent required args here.
      mustThrowWith("RTCTrackEvent wo/required args",
                    "TypeError", () => new RTCTrackEvent("track", {}));
      v2.srcObject = e.streams[0];
      resolve();
    }
  });

  runNetworkTest(async () => {
    // [TODO] re-enable HW decoder after bug 1526207 is fixed.
    if (navigator.userAgent.includes("Android")) {
      await pushPrefs(["media.navigator.mediadatadecoder_vpx_enabled", false]);
      await pushPrefs(["media.webrtc.hw.h264.enabled", false]);
    }

    v2 = createMediaElement('video', 'v2');
    is(v2.currentTime, 0, "v2.currentTime is zero at outset");

    const emitter = new VideoFrameEmitter(CaptureStreamTestHelper.prototype.blue,
                                          CaptureStreamTestHelper.prototype.green,
                                          16, 16);
    emitter.start();
    emitter.stream().getTracks().forEach(t => pc1.addTrack(t, emitter.stream()));
    let h = emitter.helper();

    let offer = await pc1.createOffer({});
    await pc1.setLocalDescription(offer);
    await pc2.setRemoteDescription(pc1.localDescription);
    // check that createAnswer accepts arg.
    let answer = await pc2.createAnswer({});
    await pc2.setLocalDescription(answer);
    await pc1.setRemoteDescription(pc2.localDescription);

    // re-negotiate to trigger the race condition in the jitter buffer
    offer = await pc1.createOffer({}); // check that createOffer accepts arg.
    await pc1.setLocalDescription(offer);
    await pc2.setRemoteDescription(pc1.localDescription);
    answer = await pc2.createAnswer({});
    await pc2.setLocalDescription(answer);
    await pc1.setRemoteDescription(pc2.localDescription);
    await delivered;

    // now verify that actually something gets rendered into the remote video
    // element.
    await h.pixelMustBecome(v2, h.blue, {
      threshold: 128,
      infoString: "pcRemote's video should become blue",
    });
    // This will verify that new changes to the canvas propagate through
    // the peerconnection
    emitter.colors(h.red, h.green)
    await h.pixelMustBecome(v2, h.red, {
      threshold: 128,
      infoString: "pcRemote's video should become red",
    });
  });
</script>
</pre>
</body>
</html>