summaryrefslogtreecommitdiffstats
path: root/dom/media/webrtc/tests/mochitests/test_peerConnection_captureStream_canvas_2d_noSSRC.html
blob: e33a7e8886728f9e43ba22334f328df993ea4b14 (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
<!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({
  title: "Canvas(2D)::CaptureStream as video-only input to peerconnection with no a=ssrc",
  visible: true
});

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

  options = options || { };
  options.ssrc = false;
  test = new PeerConnectionTest(options);
  var mediaElement;
  var h = new CaptureStreamTestHelper2D();
  var canvas = document.createElement('canvas');
  var stream;
  canvas.id = 'source_canvas';
  canvas.width = canvas.height = 16;
  document.getElementById('content').appendChild(canvas);

  test.setMediaConstraints([{video: true}], []);
  test.chain.replace("PC_LOCAL_GUM", [
    function PC_LOCAL_CANVAS_CAPTURESTREAM(test) {
      h.drawColor(canvas, h.green);
      stream = canvas.captureStream(0);
      test.pcLocal.attachLocalStream(stream);
      stream.requestFrame();
      var i = 0;
      return setInterval(function() {
        try {
          info("draw " + i ? "green" : "red");
          h.drawColor(canvas, i ? h.green : h.red);
          i = 1 - i;
          stream.requestFrame();
        } catch (e) {
          // ignore; stream might have shut down, and we don't bother clearing
          // the setInterval.
        }
      }, 500);
    }
  ]);
  test.chain.append([
    function PC_REMOTE_WAIT_FOR_REMOTE_GREEN() {
      mediaElement = test.pcRemote.remoteMediaElements[0];
      ok(!!mediaElement, "Should have remote video element for pcRemote");
      return h.pixelMustBecome(mediaElement, h.green, {
        threshold: 128,
        infoString: "pcRemote's remote should become green",
      });
    },
    function PC_LOCAL_DRAW_LOCAL_RED() {
      // After requesting a frame it will be captured at the time of next render.
      // Next render will happen at next stable state, at the earliest,
      // i.e., this order of `requestFrame(); draw();` should work.
      stream.requestFrame();
      h.drawColor(canvas, h.red);
    },
    function PC_REMOTE_WAIT_FOR_REMOTE_RED() {
      return h.pixelMustBecome(mediaElement, h.red, {
        threshold: 128,
        infoString: "pcRemote's remote should become red",
      });
    }
  ]);
  await test.run();
});
</script>
</pre>
</body>
</html>