Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <head> |
michael@0 | 4 | <title>Test tail time lifetime of DelayNode after input is disconnected</title> |
michael@0 | 5 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 6 | <script type="text/javascript" src="webaudio.js"></script> |
michael@0 | 7 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 8 | </head> |
michael@0 | 9 | <body> |
michael@0 | 10 | <pre id="test"> |
michael@0 | 11 | <script class="testbody" type="text/javascript"> |
michael@0 | 12 | |
michael@0 | 13 | // Web Audio doesn't provide a means to precisely time disconnect()s but we |
michael@0 | 14 | // can test that the output of delay nodes matches the output from their |
michael@0 | 15 | // sources before they are disconnected. |
michael@0 | 16 | |
michael@0 | 17 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 18 | |
michael@0 | 19 | const signalLength = 128; |
michael@0 | 20 | const bufferSize = 4096; |
michael@0 | 21 | const sourceCount = bufferSize / signalLength; |
michael@0 | 22 | // Delay should be long enough to allow CC to run |
michael@0 | 23 | var delayBufferCount = 20; |
michael@0 | 24 | const delayLength = delayBufferCount * bufferSize; |
michael@0 | 25 | |
michael@0 | 26 | var sourceOutput = new Float32Array(bufferSize); |
michael@0 | 27 | var delayOutputCount = 0; |
michael@0 | 28 | var sources = []; |
michael@0 | 29 | |
michael@0 | 30 | function onDelayOutput(e) { |
michael@0 | 31 | if (delayOutputCount < delayBufferCount) { |
michael@0 | 32 | delayOutputCount++; |
michael@0 | 33 | return; |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | compareChannels(e.inputBuffer.getChannelData(0), sourceOutput); |
michael@0 | 37 | e.target.onaudioprocess = null; |
michael@0 | 38 | SimpleTest.finish(); |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | function onSourceOutput(e) { |
michael@0 | 42 | // Record the first buffer |
michael@0 | 43 | e.inputBuffer.copyFromChannel(sourceOutput, 0); |
michael@0 | 44 | e.target.onaudioprocess = null; |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | function disconnectSources() { |
michael@0 | 48 | for (var i = 0; i < sourceCount; ++i) { |
michael@0 | 49 | sources[i].disconnect(); |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | SpecialPowers.forceGC(); |
michael@0 | 53 | SpecialPowers.forceCC(); |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | function startTest() { |
michael@0 | 57 | var ctx = new AudioContext(); |
michael@0 | 58 | |
michael@0 | 59 | var sourceProcessor = ctx.createScriptProcessor(bufferSize, 1, 0); |
michael@0 | 60 | sourceProcessor.onaudioprocess = onSourceOutput; |
michael@0 | 61 | // Keep audioprocess events going after source disconnect. |
michael@0 | 62 | sourceProcessor.connect(ctx.destination); |
michael@0 | 63 | |
michael@0 | 64 | var delayProcessor = ctx.createScriptProcessor(bufferSize, 1, 0); |
michael@0 | 65 | delayProcessor.onaudioprocess = onDelayOutput; |
michael@0 | 66 | // Work around bug 916387. |
michael@0 | 67 | delayProcessor.connect(ctx.destination); |
michael@0 | 68 | |
michael@0 | 69 | var delayDuration = delayLength / ctx.sampleRate; |
michael@0 | 70 | for (var i = 0; i < sourceCount; ++i) { |
michael@0 | 71 | var delay = ctx.createDelay(delayDuration); |
michael@0 | 72 | delay.delayTime.value = delayDuration; |
michael@0 | 73 | delay.connect(delayProcessor); |
michael@0 | 74 | |
michael@0 | 75 | var source = ctx.createOscillator(); |
michael@0 | 76 | source.frequency.value = 440 + 10 * i |
michael@0 | 77 | source.start(i * signalLength / ctx.sampleRate); |
michael@0 | 78 | source.stop((i + 1) * signalLength / ctx.sampleRate); |
michael@0 | 79 | source.connect(delay); |
michael@0 | 80 | source.connect(sourceProcessor); |
michael@0 | 81 | |
michael@0 | 82 | sources[i] = source; |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | // Assuming the above Web Audio operations have already scheduled an event |
michael@0 | 86 | // to run in stable state and start the graph thread, schedule a subsequent |
michael@0 | 87 | // event to disconnect the sources, which will remove main thread connection |
michael@0 | 88 | // references before it knows the graph thread has started using the source |
michael@0 | 89 | // streams. |
michael@0 | 90 | SimpleTest.executeSoon(disconnectSources); |
michael@0 | 91 | }; |
michael@0 | 92 | |
michael@0 | 93 | startTest(); |
michael@0 | 94 | </script> |
michael@0 | 95 | </pre> |
michael@0 | 96 | </body> |
michael@0 | 97 | </html> |