4 https://bugzilla.mozilla.org/show_bug.cgi?id=490705
8 <title>Media test: framebuffer size checks
</title>
9 <script type=
"text/javascript" src=
"/tests/SimpleTest/SimpleTest.js"></script>
10 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css" />
13 <a target=
"_blank" href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=490705">Mozilla Bug
490705</a>
15 <!-- mute audio, since there is no need to hear the sound for these tests -->
16 <audio id='a1' controls
></audio>
19 <script class=
"testbody" type=
"text/javascript">
20 var testFile =
"bug495794.ogg";
21 var testFileDuration =
0.30;
22 var testFileChannelCount =
6;
23 var testFileSampleRate =
48000;
24 var testFileFrameBufferLength =
6 *
1024;
28 var currentSampleOffset =
0;
29 var isTimePropertyValid = true;
31 function audioAvailable(event) {
32 var buffer = event.frameBuffer;
34 if ( (typeof event.time !==
"number") ||
35 (Math.abs(event.time - currentSampleOffset / testFileSampleRate / testFileChannelCount)
> 0.01) ) {
36 isTimePropertyValid = false;
39 currentSampleOffset += buffer.length;
42 var loadedMetadataCalled = false;
43 function loadedMetadata() {
44 loadedMetadataCalled = true;
45 var a1 = document.getElementById('a1');
46 is(a1.mozChannels, testFileChannelCount,
"mozChannels should be " + testFileChannelCount +
".");
47 is(a1.mozSampleRate, testFileSampleRate,
"mozSampleRate should be " + testFileSampleRate +
".");
48 is(a1.mozFrameBufferLength, testFileFrameBufferLength,
"default mozFrameBufferLength should be " + testFileFrameBufferLength +
".");
50 var minFailed = false;
52 a1.mozFrameBufferLength =
4;
56 ok(minFailed,
"mozFrameBufferLength min fail check");
58 var maxFailed = false;
60 a1.mozFrameBufferLength =
44444;
64 ok(maxFailed,
"mozFrameBufferLength max fail check");
66 a1.mozFrameBufferLength = testFileFrameBufferLength;
69 function checkResults() {
70 ok(loadedMetadataCalled,
"loadedmetadata event not dispatched.");
71 ok(isTimePropertyValid,
"The audioAvailable event's time attribute was invalid.");
73 var expectedOffset = Math.ceil(testFileDuration * testFileSampleRate * testFileChannelCount);
74 if (expectedOffset % testFileFrameBufferLength !==
0) {
75 expectedOffset += (testFileFrameBufferLength - (expectedOffset % testFileFrameBufferLength));
77 is(currentSampleOffset, expectedOffset,
"Check amount of signal data processed");
82 function audioEnded() {
87 var a1 = document.getElementById('a1');
88 a1.addEventListener(
"ended", audioEnded, false);
89 a1.addEventListener(
"loadedmetadata", loadedMetadata, false);
90 a1.addEventListener(
"MozAudioAvailable", audioAvailable, false);
96 window.addEventListener(
"load", function(e) {
100 SimpleTest.waitForExplicitFinish();