DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (d74eec46c4ea)

VCS Links

Line Code
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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
<!doctype html>
<html>
<head>
  <title>MediaRecorder MIMEType</title>
  <link rel="help" href="https://w3c.github.io/mediacapture-record/MediaRecorder.html#dom-mediarecorder-mimetype">
  <script src="/resources/testharness.js"></script>
  <script src="/resources/testharnessreport.js"></script>
</head>
<body>
<canvas id="canvas" width="200" height="200">
</canvas>
<script>
function createAudioStream(t) {
  const ac = new AudioContext();
  const dest = ac.createMediaStreamDestination();
  const osc = ac.createOscillator();
  osc.connect(dest);
  osc.start();
  const [track] = dest.stream.getTracks();
  t.add_cleanup(() => track.stop());
  return dest.stream;
}

function createVideoStream(t) {
  const canvas = document.getElementById("canvas");
  const ctx = canvas.getContext('2d');
  const stream = canvas.captureStream();
  const [track] = stream.getTracks();
  t.add_cleanup(() => track.stop());
  ctx.fillStyle = 'green';
  requestAnimationFrame(function draw() {
    ctx.fillRect(0, 0, canvas.width, canvas.height);
    if (track.readyState == "live") {
      requestAnimationFrame(draw);
    }
  });
  return stream;
}

function createAudioVideoStream(t) {
  return new MediaStream([
      ...createAudioStream(t).getTracks(),
      ...createVideoStream(t).getTracks(),
    ]);
}

test(t => {
  const recorder = new MediaRecorder(createAudioStream(t));
  assert_equals(recorder.mimeType, "",
    "MediaRecorder has no default MIMEtype");
}, "MediaRecorder sets no default MIMEType in the constructor for audio");

test(t => {
  const recorder = new MediaRecorder(createVideoStream(t));
  assert_equals(recorder.mimeType, "",
    "MediaRecorder has no default MIMEtype");
}, "MediaRecorder sets no default MIMEType in the constructor for video");

test(t => {
  const stream = createAudioVideoStream(t);
  const recorder = new MediaRecorder(stream);
  assert_equals(recorder.mimeType, "",
    "MediaRecorder has no default MIMEtype");
}, "MediaRecorder sets no default MIMEType in the constructor for audio/video");

test(t => {
  assert_throws("NotSupportedError",
    () => new MediaRecorder(new MediaStream(), {mimeType: "audio/banana"}));
}, "MediaRecorder invalid audio MIMEType throws");

test(t => {
  assert_false(MediaRecorder.isTypeSupported("audio/banana"));
}, "MediaRecorder invalid audio MIMEType is unsupported");

test(t => {
  assert_throws("NotSupportedError",
    () => new MediaRecorder(new MediaStream(), {mimeType: "video/pineapple"}));
}, "MediaRecorder invalid video MIMEType throws");

test(t => {
  assert_false(MediaRecorder.isTypeSupported("video/pineapple"));
}, "MediaRecorder invalid video MIMEType is unsupported");

// New MIME types could be added to this list as needed.
for (const mimeType of [
  'audio/mp4',
  'video/mp4',
  'audio/ogg',
  'audio/ogg; codecs="vorbis"',
  'audio/ogg; codecs="opus"',
  'audio/webm',
  'audio/webm; codecs="vorbis"',
  'audio/webm; codecs="opus"',
  'video/webm',
  'video/webm; codecs="vp8"',
  'video/webm; codecs="vp8, vorbis"',
  'video/webm; codecs="vp8, opus"',
  'video/webm; codecs="vp9"',
  'video/webm; codecs="vp9, vorbis"',
  'video/webm; codecs="vp9, opus"',
  'video/webm; codecs="av1"',
  'video/webm; codecs="av1, opus"',
]) {
  if (MediaRecorder.isTypeSupported(mimeType)) {
    test(t => {
      const recorder = new MediaRecorder(new MediaStream(), {mimeType});
      assert_equals(recorder.mimeType, mimeType, "Supported MIMEType is set");
    }, `Supported MIMEType ${mimeType} is set immediately after constructing`);
  } else {
    test(t => {
      assert_throws("NotSupportedError",
        () => new MediaRecorder(new MediaStream(), {mimeType}));
    }, `Unsupported MIMEType ${mimeType} throws`);
  }
}

promise_test(async t => {
  const recorder = new MediaRecorder(createAudioStream(t));
  recorder.start();
  assert_equals(recorder.mimeType, "",
    "MediaRecorder has no MIMEtype after start() for audio");

  await new Promise(r => recorder.onstart = r);
  assert_not_equals(recorder.mimeType, "",
    "MediaRecorder has a MIMEtype after 'start' for audio");
  assert_regexp_match(recorder.mimeType, /^audio\//,
    "MIMEtype has an expected media type");
  assert_regexp_match(recorder.mimeType, /^[a-z]+\/[a-z]+/,
    "MIMEtype has a container subtype");
  assert_regexp_match(recorder.mimeType, /^[a-z]+\/[a-z]+; codecs=[^,]+$/,
    "MIMEtype has one codec");
}, "MediaRecorder sets a MIMEType after 'start' for audio");

promise_test(async t => {
  const recorder = new MediaRecorder(createVideoStream(t));
  recorder.start();
  assert_equals(recorder.mimeType, "",
    "MediaRecorder has no MIMEtype after start() for video");

  await new Promise(r => recorder.onstart = r);
  assert_not_equals(recorder.mimeType, "",
    "MediaRecorder has a MIMEtype after 'start' for video");
  assert_regexp_match(recorder.mimeType, /^video\//,
    "MIMEtype has an expected media type");
  assert_regexp_match(recorder.mimeType, /^[a-z]+\/[a-z]+/,
    "MIMEtype has a container subtype");
  assert_regexp_match(recorder.mimeType, /^[a-z]+\/[a-z]+; codecs=[^,]+$/,
    "MIMEtype has one codec");
}, "MediaRecorder sets a MIMEType after 'start' for video");

promise_test(async t => {
  const recorder = new MediaRecorder(createAudioVideoStream(t));
  recorder.start();
  assert_equals(recorder.mimeType, "",
    "MediaRecorder has no MIMEtype after start() for audio/video");

  await new Promise(r => recorder.onstart = r);
  assert_not_equals(recorder.mimeType, "",
    "MediaRecorder has a MIMEtype after 'start' for audio/video");
  assert_regexp_match(recorder.mimeType, /^video\//,
    "MIMEtype has an expected media type");
  assert_regexp_match(recorder.mimeType, /^[a-z]+\/[a-z]+/,
    "MIMEtype has a container subtype");
  assert_regexp_match(recorder.mimeType, /^[a-z]+\/[a-z]+; codecs=[^,]+,[^,]+$/,
    "MIMEtype has two codecs");
}, "MediaRecorder sets a MIMEType after 'start' for audio/video");
</script>
</body>
</html>