Bug 916384 - Stop calling onaudioprocess on the ScriptProcessorNode if it has no inputs and outputs. r=roc

Quoting the spec: "audioprocess events are only dispatched if the
ScriptProcessorNode has at least one input or one output connected".

--HG--
extra : rebase_source : 93881fb4395744dc0adbb6df7ee146ef70ce42d2
This commit is contained in:
Paul Adenot 2013-12-10 14:41:41 +01:00
Родитель 732a48c7f8
Коммит b7e2b9858e
5 изменённых файлов: 74 добавлений и 0 удалений

Просмотреть файл

@ -445,6 +445,10 @@ public:
{
mConsumers.RemoveElement(aPort);
}
uint32_t ConsumerCount()
{
return mConsumers.Length();
}
const StreamBuffer& GetStreamBuffer() { return mBuffer; }
GraphTime GetStreamBufferStartTime() { return mBufferStartTime; }
/**
@ -944,6 +948,10 @@ public:
{
return mInputs.Contains(aPort);
}
uint32_t InputPortCount()
{
return mInputs.Length();
}
virtual void DestroyImpl();
/**
* This gets called after we've computed the blocking states for all

Просмотреть файл

@ -67,6 +67,13 @@ private:
return front;
}
// Empties the buffer queue.
void Clear()
{
mMutex.AssertCurrentThreadOwns();
mBufferList.clear();
}
private:
typedef std::deque<AudioChunk> BufferList;
@ -167,6 +174,18 @@ public:
return mDelaySoFar == TRACK_TICKS_MAX ? 0 : mDelaySoFar;
}
void Reset()
{
MOZ_ASSERT(!NS_IsMainThread());
mDelaySoFar = TRACK_TICKS_MAX;
mLatency = 0.0f;
{
MutexAutoLock lock(mOutputQueue.Lock());
mOutputQueue.Clear();
}
mLastEventTime = TimeStamp();
}
private:
OutputQueue mOutputQueue;
// How much delay we've seen so far. This measures the amount of delay
@ -224,6 +243,18 @@ public:
return;
}
// This node is not connected to anything. Per spec, we don't fire the
// onaudioprocess event. We also want to clear out the input and output
// buffer queue, and output a null buffer.
if (!(aStream->ConsumerCount() ||
aStream->AsProcessedStream()->InputPortCount())) {
aOutput->SetNull(WEBAUDIO_BLOCK_SIZE);
mSharedBuffers->Reset();
mSeenNonSilenceInput = false;
mInputWriteIndex = 0;
return;
}
// First, record our input buffer
for (uint32_t i = 0; i < mInputChannels.Length(); ++i) {
if (aInput.IsNull()) {

Просмотреть файл

@ -108,6 +108,7 @@ support-files =
[test_scriptProcessorNode.html]
[test_scriptProcessorNodeChannelCount.html]
[test_scriptProcessorNodeZeroInputOutput.html]
[test_scriptProcessorNodeNotConnected.html]
[test_singleSourceDest.html]
[test_waveShaper.html]
[test_waveShaperNoCurve.html]

Просмотреть файл

@ -0,0 +1,32 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test AudioBufferSourceNode: should not fire audioprocess if not connected.</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="webaudio.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
addLoadEvent(function() {
var context = new AudioContext();
var sp = context.createScriptProcessor(2048, 2, 2);
sp.onaudioprocess = function(e) {
ok(false, "Should not call onaudioprocess if the node is not connected.");
sp.onaudioprocess = null;
SimpleTest.finish();
};
setTimeout(function() {
if (sp.onaudioprocess) {
ok(true, "onaudioprocess not fired.");
SimpleTest.finish();
}
}, 4000);
});
</script>
</pre>
</body>
</html>

Просмотреть файл

@ -28,7 +28,9 @@ addLoadEvent(function() {
SimpleTest.finish();
};
sp.connect(context.destination);
};
sp.connect(context.destination);
});
</script>