Chromium Code Reviews| Index: third_party/WebKit/Source/modules/webaudio/ScriptProcessorNode.cpp |
| diff --git a/third_party/WebKit/Source/modules/webaudio/ScriptProcessorNode.cpp b/third_party/WebKit/Source/modules/webaudio/ScriptProcessorNode.cpp |
| index 6f26b7d3d951a565623fab7b6ed7e101915fbb99..d1489687075be8f0c26059beb5404e14edb313cd 100644 |
| --- a/third_party/WebKit/Source/modules/webaudio/ScriptProcessorNode.cpp |
| +++ b/third_party/WebKit/Source/modules/webaudio/ScriptProcessorNode.cpp |
| @@ -259,8 +259,75 @@ static size_t chooseBufferSize() |
| return bufferSize; |
| } |
| -ScriptProcessorNode* ScriptProcessorNode::create(AbstractAudioContext& context, float sampleRate, size_t bufferSize, unsigned numberOfInputChannels, unsigned numberOfOutputChannels) |
| +ScriptProcessorNode* ScriptProcessorNode::create( |
| + AbstractAudioContext& context, |
| + ExceptionState& exceptionState) |
| { |
| + DCHECK(isMainThread()); |
| + |
|
hongchan
2016/05/13 21:35:48
Let's add a comment here. In fact, I think we shou
Raymond Toy
2016/05/16 23:11:53
Done.
|
| + return create(context, 0, 2, 2, exceptionState); |
| +} |
| + |
| +ScriptProcessorNode* ScriptProcessorNode::create( |
| + AbstractAudioContext& context, |
| + size_t bufferSize, |
| + ExceptionState& exceptionState) |
| +{ |
| + DCHECK(isMainThread()); |
| + |
| + return create(context, bufferSize, 2, 2, exceptionState); |
| +} |
| + |
| +ScriptProcessorNode* ScriptProcessorNode::create( |
| + AbstractAudioContext& context, |
| + size_t bufferSize, |
| + unsigned numberOfInputChannels, |
| + ExceptionState& exceptionState) |
| +{ |
| + DCHECK(isMainThread()); |
| + |
| + return create(context, bufferSize, numberOfInputChannels, 2, exceptionState); |
| +} |
| + |
| +ScriptProcessorNode* ScriptProcessorNode::create( |
| + AbstractAudioContext& context, |
| + size_t bufferSize, |
| + unsigned numberOfInputChannels, |
| + unsigned numberOfOutputChannels, |
| + ExceptionState& exceptionState) |
| +{ |
| + DCHECK(isMainThread()); |
| + |
| + if (context.isContextClosed()) { |
| + context.throwExceptionForClosedState(exceptionState); |
| + return nullptr; |
| + } |
| + |
| + if (numberOfInputChannels == 0 && numberOfOutputChannels == 0) { |
| + exceptionState.throwDOMException( |
| + IndexSizeError, |
| + "number of input channels and output channels cannot both be zero."); |
| + return nullptr; |
| + } |
| + |
| + if (numberOfInputChannels > AbstractAudioContext::maxNumberOfChannels()) { |
| + exceptionState.throwDOMException( |
| + IndexSizeError, |
| + "number of input channels (" + String::number(numberOfInputChannels) |
| + + ") exceeds maximum (" |
| + + String::number(AbstractAudioContext::maxNumberOfChannels()) + ")."); |
| + return nullptr; |
| + } |
| + |
| + if (numberOfOutputChannels > AbstractAudioContext::maxNumberOfChannels()) { |
| + exceptionState.throwDOMException( |
| + IndexSizeError, |
| + "number of output channels (" + String::number(numberOfInputChannels) |
| + + ") exceeds maximum (" |
| + + String::number(AbstractAudioContext::maxNumberOfChannels()) + ")."); |
| + return nullptr; |
| + } |
| + |
| // Check for valid buffer size. |
| switch (bufferSize) { |
| case 0: |
| @@ -275,19 +342,21 @@ ScriptProcessorNode* ScriptProcessorNode::create(AbstractAudioContext& context, |
| case 16384: |
| break; |
| default: |
| + exceptionState.throwDOMException( |
| + IndexSizeError, |
| + "buffer size (" + String::number(bufferSize) |
| + + ") must be 0 or a power of two between 256 and 16384."); |
| return nullptr; |
| } |
| - if (!numberOfInputChannels && !numberOfOutputChannels) |
| - return nullptr; |
| - |
| - if (numberOfInputChannels > AbstractAudioContext::maxNumberOfChannels()) |
| - return nullptr; |
| + ScriptProcessorNode* node = new ScriptProcessorNode(context, context.sampleRate(), bufferSize, numberOfInputChannels, numberOfOutputChannels); |
| - if (numberOfOutputChannels > AbstractAudioContext::maxNumberOfChannels()) |
| - return nullptr; |
| + if (node) { |
| + // context keeps reference until we stop making javascript rendering callbacks |
| + context.notifySourceNodeStartedProcessing(node); |
| + } |
| - return new ScriptProcessorNode(context, sampleRate, bufferSize, numberOfInputChannels, numberOfOutputChannels); |
| + return node; |
| } |
| size_t ScriptProcessorNode::bufferSize() const |