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 (409f3966645a)

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
<!DOCTYPE HTML>
<html>
<head>
  <title>Test MediaRecorder Record AudioContext with four channels</title>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
  <script type="text/javascript" src="manifest.js"></script>
</head>
<body>

<script class="testbody" type="text/javascript">

function startTest() {
  var context = new AudioContext();
  var buffer = context.createBuffer(4, 80920, context.sampleRate);
  for (var i = 0; i < 80920; ++i) {
    for(var j = 0; j < 4; ++j) {
      buffer.getChannelData(j)[i] = Math.sin(1000 * 2 * Math.PI * i / context.sampleRate);
    }
  }

  var source = context.createBufferSource();
  source.buffer = buffer;
  source.loop = true;
  var dest = context.createMediaStreamDestination();
  var stopTriggered = false;
  var onstopTriggered = false;
  dest.channelCount = 4;
  var expectedMimeType = 'audio/ogg';
  var totalBlobSize = 0;
  source.channelCountMode = 'explicit';
  source.connect(dest);
  var elem = document.createElement('audio');
  elem.srcObject = dest.stream;
  mMediaStream = dest.stream;
  source.start(0);
  elem.play();
  mMediaRecorder = new MediaRecorder(dest.stream);
  mMediaRecorder.onwarning = function() {
    ok(false, 'onwarning unexpectedly fired');
  };

  mMediaRecorder.onerror = function() {
    ok(false, 'onerror unexpectedly fired');
  };

  mMediaRecorder.onstop = function() {
    ok(true, 'onstop fired successfully');
    is(mMediaRecorder.state, 'inactive', 'check recording status is inactive');
    onstopTriggered = true;
    SimpleTest.finish();
  };
  mMediaRecorder.ondataavailable = function (e) {
    if (mMediaRecorder.state == 'recording') {
      ok(e.data.size > 0, 'check blob has data');
    }
    totalBlobSize += e.data.size;
    ok(totalBlobSize > 0, 'check the totalBlobSize');
    is(mMediaRecorder.mimeType, expectedMimeType, 'blob should has mimetype, return ' + mMediaRecorder.mimeType);
    if (!stopTriggered) {
      mMediaRecorder.stop();
      stopTriggered = true;
    } else if (onstopTriggered) {
      ok(false, 'ondataavailable should come before onstop event');
    }
  };
  try {
    mMediaRecorder.start(1000);
    is('recording', mMediaRecorder.state, "check record state recording");
  } catch (e) {
    ok(false, 'Can t record audio context');
  }
}

startTest();
SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>
</html>