Changeset 217919 in webkit


Ignore:
Timestamp:
Jun 7, 2017 9:31:31 PM (7 years ago)
Author:
jer.noble@apple.com
Message:

[Web Audio] createScriptProcessor throws IndexSizeError for valid arguments
https://bugs.webkit.org/show_bug.cgi?id=173022

Reviewed by Sam Weinig.

Source/WebCore:

Updated test: webaudio/javascriptaudionode.html

The Web Audio spec (<https://webaudio.github.io/web-audio-api/>, 06 June 2017) defines a default behavior when
clients pass in a value of 0 for bufferSize to the createScriptProcessor() method.

  • Modules/webaudio/AudioContext.cpp:

(WebCore::AudioContext::createScriptProcessor):

  • Modules/webaudio/AudioContext.idl:
  • Modules/webaudio/ScriptProcessorNode.cpp:

(WebCore::ScriptProcessorNode::create):

  • Modules/webaudio/ScriptProcessorNode.h:

LayoutTests:

  • webaudio/javascriptaudionode-expected.txt:
  • webaudio/javascriptaudionode.html:
Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r217917 r217919  
     12017-06-07  Jer Noble  <jer.noble@apple.com>
     2
     3        [Web Audio] createScriptProcessor throws IndexSizeError for valid arguments
     4        https://bugs.webkit.org/show_bug.cgi?id=173022
     5
     6        Reviewed by Sam Weinig.
     7
     8        * webaudio/javascriptaudionode-expected.txt:
     9        * webaudio/javascriptaudionode.html:
     10
    1112017-06-07  Chris Dumez  <cdumez@apple.com>
    212
  • trunk/LayoutTests/webaudio/javascriptaudionode-expected.txt

    r146040 r217919  
    99PASS Successfully created ScriptProcessorNode with numberOfInputChannels = 0 and numberOfOutputChannels = 2.
    1010PASS Exception was thrown for illegal bufferSize.
     11PASS Successfully created ScriptProcessorNode with bufferSize = 0.
    1112PASS Successfully created ScriptProcessorNode with bufferSize = 256.
    1213PASS Successfully created ScriptProcessorNode with bufferSize = 512.
  • trunk/LayoutTests/webaudio/javascriptaudionode.html

    r217243 r217919  
    124124    }
    125125
     126    doBufferSizeTest(0);
    126127    doBufferSizeTest(256);
    127128    doBufferSizeTest(512);
  • trunk/Source/WebCore/ChangeLog

    r217917 r217919  
     12017-06-07  Jer Noble  <jer.noble@apple.com>
     2
     3        [Web Audio] createScriptProcessor throws IndexSizeError for valid arguments
     4        https://bugs.webkit.org/show_bug.cgi?id=173022
     5
     6        Reviewed by Sam Weinig.
     7
     8        Updated test: webaudio/javascriptaudionode.html
     9
     10        The Web Audio spec (<https://webaudio.github.io/web-audio-api/>, 06 June 2017) defines a default behavior when
     11        clients pass in a value of 0 for bufferSize to the createScriptProcessor() method.
     12
     13        * Modules/webaudio/AudioContext.cpp:
     14        (WebCore::AudioContext::createScriptProcessor):
     15        * Modules/webaudio/AudioContext.idl:
     16        * Modules/webaudio/ScriptProcessorNode.cpp:
     17        (WebCore::ScriptProcessorNode::create):
     18        * Modules/webaudio/ScriptProcessorNode.h:
     19
    1202017-06-07  Chris Dumez  <cdumez@apple.com>
    221
  • trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp

    r216886 r217919  
    3838#include "AudioNodeInput.h"
    3939#include "AudioNodeOutput.h"
     40#include "AudioSession.h"
    4041#include "BiquadFilterNode.h"
    4142#include "ChannelMergerNode.h"
     
    489490    ASSERT(isMainThread());
    490491    lazyInitialize();
     492
     493    // W3C Editor's Draft 06 June 2017
     494    //  https://webaudio.github.io/web-audio-api/#widl-BaseAudioContext-createScriptProcessor-ScriptProcessorNode-unsigned-long-bufferSize-unsigned-long-numberOfInputChannels-unsigned-long-numberOfOutputChannels
     495
     496    // The bufferSize parameter determines the buffer size in units of sample-frames. If it's not passed in,
     497    // or if the value is 0, then the implementation will choose the best buffer size for the given environment,
     498    // which will be constant power of 2 throughout the lifetime of the node. ... If the value of this parameter
     499    // is not one of the allowed power-of-2 values listed above, an IndexSizeError must be thrown.
     500    switch (bufferSize) {
     501    case 0:
     502#if USE(AUDIO_SESSION)
     503        // Pick a value between 256 (2^8) and 16384 (2^14), based on the buffer size of the current AudioSession:
     504        bufferSize = 1 << std::max<size_t>(8, std::min<size_t>(14, std::log2(AudioSession::sharedSession().bufferSize())));
     505#else
     506        bufferSize = 2048;
     507#endif
     508        break;
     509    case 256:
     510    case 512:
     511    case 1024:
     512    case 2048:
     513    case 4096:
     514    case 8192:
     515    case 16384:
     516        break;
     517    default:
     518        return Exception { INDEX_SIZE_ERR };
     519    }
     520
     521    // An IndexSizeError exception must be thrown if bufferSize or numberOfInputChannels or numberOfOutputChannels
     522    // are outside the valid range. It is invalid for both numberOfInputChannels and numberOfOutputChannels to be zero.
     523    // In this case an IndexSizeError must be thrown.
     524
     525    if (!numberOfInputChannels && !numberOfOutputChannels)
     526        return Exception { NOT_SUPPORTED_ERR };
     527
     528    // This parameter [numberOfInputChannels] determines the number of channels for this node's input. Values of
     529    // up to 32 must be supported. A NotSupportedError must be thrown if the number of channels is not supported.
     530
     531    if (numberOfInputChannels > maxNumberOfChannels())
     532        return Exception { NOT_SUPPORTED_ERR };
     533
     534    // This parameter [numberOfOutputChannels] determines the number of channels for this node's output. Values of
     535    // up to 32 must be supported. A NotSupportedError must be thrown if the number of channels is not supported.
     536
     537    if (numberOfOutputChannels > maxNumberOfChannels())
     538        return Exception { NOT_SUPPORTED_ERR };
     539
    491540    auto node = ScriptProcessorNode::create(*this, m_destinationNode->sampleRate(), bufferSize, numberOfInputChannels, numberOfOutputChannels);
    492541
    493     if (!node)
    494         return Exception { INDEX_SIZE_ERR };
    495 
    496     refNode(*node); // context keeps reference until we stop making javascript rendering callbacks
    497     return node.releaseNonNull();
     542    refNode(node); // context keeps reference until we stop making javascript rendering callbacks
     543    return WTFMove(node);
    498544}
    499545
  • trunk/Source/WebCore/Modules/webaudio/AudioContext.idl

    r208474 r217919  
    8686    DynamicsCompressorNode createDynamicsCompressor();
    8787    AnalyserNode createAnalyser();
    88     [MayThrowException] ScriptProcessorNode createScriptProcessor(unsigned long bufferSize, optional unsigned long numberOfInputChannels = 2, optional unsigned long numberOfOutputChannels = 2);
     88    [MayThrowException] ScriptProcessorNode createScriptProcessor(optional unsigned long bufferSize = 0, optional unsigned long numberOfInputChannels = 2, optional unsigned long numberOfOutputChannels = 2);
    8989    OscillatorNode createOscillator();
    9090    [MayThrowException] PeriodicWave createPeriodicWave(Float32Array real, Float32Array imag);
  • trunk/Source/WebCore/Modules/webaudio/ScriptProcessorNode.cpp

    r210621 r217919  
    4242namespace WebCore {
    4343
    44 RefPtr<ScriptProcessorNode> ScriptProcessorNode::create(AudioContext& context, float sampleRate, size_t bufferSize, unsigned numberOfInputChannels, unsigned numberOfOutputChannels)
    45 {
    46     // Check for valid buffer size.
    47     switch (bufferSize) {
    48     case 256:
    49     case 512:
    50     case 1024:
    51     case 2048:
    52     case 4096:
    53     case 8192:
    54     case 16384:
    55         break;
    56     default:
    57         return nullptr;
    58     }
    59 
    60     if (!numberOfInputChannels && !numberOfOutputChannels)
    61         return nullptr;
    62 
    63     if (numberOfInputChannels > AudioContext::maxNumberOfChannels())
    64         return nullptr;
    65 
    66     if (numberOfOutputChannels > AudioContext::maxNumberOfChannels())
    67         return nullptr;
    68 
     44Ref<ScriptProcessorNode> ScriptProcessorNode::create(AudioContext& context, float sampleRate, size_t bufferSize, unsigned numberOfInputChannels, unsigned numberOfOutputChannels)
     45{
    6946    return adoptRef(*new ScriptProcessorNode(context, sampleRate, bufferSize, numberOfInputChannels, numberOfOutputChannels));
    7047}
  • trunk/Source/WebCore/Modules/webaudio/ScriptProcessorNode.h

    r208646 r217919  
    5252    // Lower numbers for bufferSize will result in a lower (better) latency. Higher numbers will be necessary to avoid audio breakup and glitches.
    5353    // The value chosen must carefully balance between latency and audio quality.
    54     static RefPtr<ScriptProcessorNode> create(AudioContext&, float sampleRate, size_t bufferSize, unsigned numberOfInputChannels, unsigned numberOfOutputChannels);
     54    static Ref<ScriptProcessorNode> create(AudioContext&, float sampleRate, size_t bufferSize, unsigned numberOfInputChannels, unsigned numberOfOutputChannels);
    5555
    5656    virtual ~ScriptProcessorNode();
Note: See TracChangeset for help on using the changeset viewer.