⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 244774 in webkit


Ignore:
Timestamp:
Apr 30, 2019, 8:17:07 AM (7 years ago)
Author:
youenn@apple.com
Message:

Reject/throw when calling AudioContext methods on a stopped AudioContext
https://bugs.webkit.org/show_bug.cgi?id=197391

Reviewed by Eric Carlson.

Source/WebCore:

Return InvalidStateError in that case.
ASSERT that we do not call lazyInitialize after being stopped
since this would mean we are doing unneeded processing.

Test: http/wpt/webaudio/audiocontext-stopped.html

  • Modules/webaudio/AudioContext.cpp:

(WebCore::AudioContext::lazyInitialize):
(WebCore::AudioContext::createBufferSource):
(WebCore::AudioContext::createMediaElementSource):
(WebCore::AudioContext::createMediaStreamSource):
(WebCore::AudioContext::createMediaStreamDestination):
(WebCore::AudioContext::createScriptProcessor):
(WebCore::AudioContext::createBiquadFilter):
(WebCore::AudioContext::createWaveShaper):
(WebCore::AudioContext::createPanner):
(WebCore::AudioContext::createConvolver):
(WebCore::AudioContext::createDynamicsCompressor):
(WebCore::AudioContext::createAnalyser):
(WebCore::AudioContext::createGain):
(WebCore::AudioContext::createDelay):
(WebCore::AudioContext::createChannelSplitter):
(WebCore::AudioContext::createChannelMerger):
(WebCore::AudioContext::createOscillator):
(WebCore::AudioContext::createPeriodicWave):
(WebCore::AudioContext::startRendering):
(WebCore::AudioContext::suspend):
(WebCore::AudioContext::resume):
(WebCore::AudioContext::close):

  • Modules/webaudio/AudioContext.h:
  • Modules/webaudio/AudioContext.idl:

LayoutTests:

  • http/wpt/webaudio/audiocontext-stopped-expected.txt: Added.
  • http/wpt/webaudio/audiocontext-stopped.html: Added.
  • http/wpt/webaudio/resources/audiocontext-stopped-iframe.html: Added.
  • platform/win/TestExpectations: Skip test for win.
Location:
trunk
Files:
5 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r244766 r244774  
     12019-04-30  Youenn Fablet  <youenn@apple.com>
     2
     3        Reject/throw when calling AudioContext methods on a stopped AudioContext
     4        https://bugs.webkit.org/show_bug.cgi?id=197391
     5
     6        Reviewed by Eric Carlson.
     7
     8        * http/wpt/webaudio/audiocontext-stopped-expected.txt: Added.
     9        * http/wpt/webaudio/audiocontext-stopped.html: Added.
     10        * http/wpt/webaudio/resources/audiocontext-stopped-iframe.html: Added.
     11        * platform/win/TestExpectations: Skip test for win.
     12
    1132019-04-30  Carlos Garcia Campos  <cgarcia@igalia.com>
    214
  • trunk/LayoutTests/platform/win/TestExpectations

    r244685 r244774  
    495495# TODO For now, Web Audio tests are disabled
    496496webkit.org/b/86914 webaudio/ [ Skip ]
     497webkit.org/b/86914 http/wpt/webaudio/ [ Skip ]
    497498webkit.org/b/86914 fast/history/page-cache-closed-audiocontext.html [ Skip ]
    498499webkit.org/b/86914 fast/history/page-cache-running-audiocontext.html [ Skip ]
  • trunk/Source/WebCore/ChangeLog

    r244773 r244774  
     12019-04-30  Youenn Fablet  <youenn@apple.com>
     2
     3        Reject/throw when calling AudioContext methods on a stopped AudioContext
     4        https://bugs.webkit.org/show_bug.cgi?id=197391
     5
     6        Reviewed by Eric Carlson.
     7
     8        Return InvalidStateError in that case.
     9        ASSERT that we do not call lazyInitialize after being stopped
     10        since this would mean we are doing unneeded processing.
     11
     12        Test: http/wpt/webaudio/audiocontext-stopped.html
     13
     14        * Modules/webaudio/AudioContext.cpp:
     15        (WebCore::AudioContext::lazyInitialize):
     16        (WebCore::AudioContext::createBufferSource):
     17        (WebCore::AudioContext::createMediaElementSource):
     18        (WebCore::AudioContext::createMediaStreamSource):
     19        (WebCore::AudioContext::createMediaStreamDestination):
     20        (WebCore::AudioContext::createScriptProcessor):
     21        (WebCore::AudioContext::createBiquadFilter):
     22        (WebCore::AudioContext::createWaveShaper):
     23        (WebCore::AudioContext::createPanner):
     24        (WebCore::AudioContext::createConvolver):
     25        (WebCore::AudioContext::createDynamicsCompressor):
     26        (WebCore::AudioContext::createAnalyser):
     27        (WebCore::AudioContext::createGain):
     28        (WebCore::AudioContext::createDelay):
     29        (WebCore::AudioContext::createChannelSplitter):
     30        (WebCore::AudioContext::createChannelMerger):
     31        (WebCore::AudioContext::createOscillator):
     32        (WebCore::AudioContext::createPeriodicWave):
     33        (WebCore::AudioContext::startRendering):
     34        (WebCore::AudioContext::suspend):
     35        (WebCore::AudioContext::resume):
     36        (WebCore::AudioContext::close):
     37        * Modules/webaudio/AudioContext.h:
     38        * Modules/webaudio/AudioContext.idl:
     39
    1402019-04-30  Youenn Fablet  <youenn@apple.com>
    241
  • trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp

    r244771 r244774  
    217217void AudioContext::lazyInitialize()
    218218{
     219    ASSERT(!m_isStopScheduled);
     220
    219221    if (m_isInitialized)
    220222        return;
     
    431433}
    432434
    433 Ref<AudioBufferSourceNode> AudioContext::createBufferSource()
    434 {
    435     ALWAYS_LOG(LOGIDENTIFIER);
    436    
    437     ASSERT(isMainThread());
     435ExceptionOr<Ref<AudioBufferSourceNode>> AudioContext::createBufferSource()
     436{
     437    ALWAYS_LOG(LOGIDENTIFIER);
     438
     439    ASSERT(isMainThread());
     440
     441    if (m_isStopScheduled)
     442        return Exception { InvalidStateError };
     443
    438444    lazyInitialize();
    439445    Ref<AudioBufferSourceNode> node = AudioBufferSourceNode::create(*this, m_destinationNode->sampleRate());
     
    451457{
    452458    ALWAYS_LOG(LOGIDENTIFIER);
    453    
    454     ASSERT(isMainThread());
    455     lazyInitialize();
    456    
    457     if (mediaElement.audioSourceNode())
    458         return Exception { InvalidStateError };
    459 
     459
     460    ASSERT(isMainThread());
     461
     462    if (m_isStopScheduled || mediaElement.audioSourceNode())
     463        return Exception { InvalidStateError };
     464
     465    lazyInitialize();
     466   
    460467    auto node = MediaElementAudioSourceNode::create(*this, mediaElement);
    461468
     
    475482   
    476483    ASSERT(isMainThread());
     484
     485    if (m_isStopScheduled)
     486        return Exception { InvalidStateError };
    477487
    478488    auto audioTracks = mediaStream.getAudioTracks();
     
    499509}
    500510
    501 Ref<MediaStreamAudioDestinationNode> AudioContext::createMediaStreamDestination()
    502 {
     511ExceptionOr<Ref<MediaStreamAudioDestinationNode>> AudioContext::createMediaStreamDestination()
     512{
     513    if (m_isStopScheduled)
     514        return Exception { InvalidStateError };
     515
    503516    // FIXME: Add support for an optional argument which specifies the number of channels.
    504517    // FIXME: The default should probably be stereo instead of mono.
     
    513526   
    514527    ASSERT(isMainThread());
     528
     529    if (m_isStopScheduled)
     530        return Exception { InvalidStateError };
     531
    515532    lazyInitialize();
    516533
     
    568585}
    569586
    570 Ref<BiquadFilterNode> AudioContext::createBiquadFilter()
    571 {
    572     ALWAYS_LOG(LOGIDENTIFIER);
    573    
    574     ASSERT(isMainThread());
    575     lazyInitialize();
     587ExceptionOr<Ref<BiquadFilterNode>> AudioContext::createBiquadFilter()
     588{
     589    ALWAYS_LOG(LOGIDENTIFIER);
     590   
     591    ASSERT(isMainThread());
     592    if (m_isStopScheduled)
     593        return Exception { InvalidStateError };
     594
     595    lazyInitialize();
     596
    576597    return BiquadFilterNode::create(*this, m_destinationNode->sampleRate());
    577598}
    578599
    579 Ref<WaveShaperNode> AudioContext::createWaveShaper()
    580 {
    581     ALWAYS_LOG(LOGIDENTIFIER);
    582    
    583     ASSERT(isMainThread());
     600ExceptionOr<Ref<WaveShaperNode>> AudioContext::createWaveShaper()
     601{
     602    ALWAYS_LOG(LOGIDENTIFIER);
     603   
     604    ASSERT(isMainThread());
     605    if (m_isStopScheduled)
     606        return Exception { InvalidStateError };
     607
    584608    lazyInitialize();
    585609    return WaveShaperNode::create(*this);
    586610}
    587611
    588 Ref<PannerNode> AudioContext::createPanner()
    589 {
    590     ALWAYS_LOG(LOGIDENTIFIER);
    591    
    592     ASSERT(isMainThread());
     612ExceptionOr<Ref<PannerNode>> AudioContext::createPanner()
     613{
     614    ALWAYS_LOG(LOGIDENTIFIER);
     615   
     616    ASSERT(isMainThread());
     617    if (m_isStopScheduled)
     618        return Exception { InvalidStateError };
     619
    593620    lazyInitialize();
    594621    return PannerNode::create(*this, m_destinationNode->sampleRate());
    595622}
    596623
    597 Ref<ConvolverNode> AudioContext::createConvolver()
    598 {
    599     ALWAYS_LOG(LOGIDENTIFIER);
    600    
    601     ASSERT(isMainThread());
     624ExceptionOr<Ref<ConvolverNode>> AudioContext::createConvolver()
     625{
     626    ALWAYS_LOG(LOGIDENTIFIER);
     627   
     628    ASSERT(isMainThread());
     629    if (m_isStopScheduled)
     630        return Exception { InvalidStateError };
     631
    602632    lazyInitialize();
    603633    return ConvolverNode::create(*this, m_destinationNode->sampleRate());
    604634}
    605635
    606 Ref<DynamicsCompressorNode> AudioContext::createDynamicsCompressor()
    607 {
    608     ALWAYS_LOG(LOGIDENTIFIER);
    609    
    610     ASSERT(isMainThread());
     636ExceptionOr<Ref<DynamicsCompressorNode>> AudioContext::createDynamicsCompressor()
     637{
     638    ALWAYS_LOG(LOGIDENTIFIER);
     639   
     640    ASSERT(isMainThread());
     641    if (m_isStopScheduled)
     642        return Exception { InvalidStateError };
     643
    611644    lazyInitialize();
    612645    return DynamicsCompressorNode::create(*this, m_destinationNode->sampleRate());
    613646}
    614647
    615 Ref<AnalyserNode> AudioContext::createAnalyser()
    616 {
    617     ALWAYS_LOG(LOGIDENTIFIER);
    618    
    619     ASSERT(isMainThread());
     648ExceptionOr<Ref<AnalyserNode>> AudioContext::createAnalyser()
     649{
     650    ALWAYS_LOG(LOGIDENTIFIER);
     651   
     652    ASSERT(isMainThread());
     653    if (m_isStopScheduled)
     654        return Exception { InvalidStateError };
     655
    620656    lazyInitialize();
    621657    return AnalyserNode::create(*this, m_destinationNode->sampleRate());
    622658}
    623659
    624 Ref<GainNode> AudioContext::createGain()
    625 {
    626     ALWAYS_LOG(LOGIDENTIFIER);
    627    
    628     ASSERT(isMainThread());
     660ExceptionOr<Ref<GainNode>> AudioContext::createGain()
     661{
     662    ALWAYS_LOG(LOGIDENTIFIER);
     663   
     664    ASSERT(isMainThread());
     665    if (m_isStopScheduled)
     666        return Exception { InvalidStateError };
     667
    629668    lazyInitialize();
    630669    return GainNode::create(*this, m_destinationNode->sampleRate());
     
    636675   
    637676    ASSERT(isMainThread());
     677    if (m_isStopScheduled)
     678        return Exception { InvalidStateError };
     679
    638680    lazyInitialize();
    639681    return DelayNode::create(*this, m_destinationNode->sampleRate(), maxDelayTime);
     
    645687   
    646688    ASSERT(isMainThread());
     689    if (m_isStopScheduled)
     690        return Exception { InvalidStateError };
     691
    647692    lazyInitialize();
    648693    auto node = ChannelSplitterNode::create(*this, m_destinationNode->sampleRate(), numberOfOutputs);
     
    657702   
    658703    ASSERT(isMainThread());
     704    if (m_isStopScheduled)
     705        return Exception { InvalidStateError };
     706
    659707    lazyInitialize();
    660708    auto node = ChannelMergerNode::create(*this, m_destinationNode->sampleRate(), numberOfInputs);
     
    664712}
    665713
    666 Ref<OscillatorNode> AudioContext::createOscillator()
    667 {
    668     ALWAYS_LOG(LOGIDENTIFIER);
    669    
    670     ASSERT(isMainThread());
     714ExceptionOr<Ref<OscillatorNode>> AudioContext::createOscillator()
     715{
     716    ALWAYS_LOG(LOGIDENTIFIER);
     717   
     718    ASSERT(isMainThread());
     719    if (m_isStopScheduled)
     720        return Exception { InvalidStateError };
     721
    671722    lazyInitialize();
    672723
     
    685736   
    686737    ASSERT(isMainThread());
     738    if (m_isStopScheduled)
     739        return Exception { InvalidStateError };
     740
    687741    if (real.length() != imaginary.length() || (real.length() > MaxPeriodicWaveLength) || !real.length())
    688742        return Exception { IndexSizeError };
     
    10791133{
    10801134    ALWAYS_LOG(LOGIDENTIFIER);
    1081     if (!willBeginPlayback())
     1135    if (m_isStopScheduled || !willBeginPlayback())
    10821136        return;
    10831137
     
    11511205void AudioContext::suspend(DOMPromiseDeferred<void>&& promise)
    11521206{
    1153     if (isOfflineContext()) {
     1207    if (isOfflineContext() || m_isStopScheduled) {
    11541208        promise.reject(InvalidStateError);
    11551209        return;
     
    11801234void AudioContext::resume(DOMPromiseDeferred<void>&& promise)
    11811235{
    1182     if (isOfflineContext()) {
     1236    if (isOfflineContext() || m_isStopScheduled) {
    11831237        promise.reject(InvalidStateError);
    11841238        return;
     
    12091263void AudioContext::close(DOMPromiseDeferred<void>&& promise)
    12101264{
    1211     if (isOfflineContext()) {
     1265    if (isOfflineContext() || m_isStopScheduled) {
    12121266        promise.reject(InvalidStateError);
    12131267        return;
  • trunk/Source/WebCore/Modules/webaudio/AudioContext.h

    r243887 r244774  
    135135
    136136    // The AudioNode create methods are called on the main thread (from JavaScript).
    137     Ref<AudioBufferSourceNode> createBufferSource();
     137    ExceptionOr<Ref<AudioBufferSourceNode>> createBufferSource();
    138138#if ENABLE(VIDEO)
    139139    ExceptionOr<Ref<MediaElementAudioSourceNode>> createMediaElementSource(HTMLMediaElement&);
     
    141141#if ENABLE(MEDIA_STREAM)
    142142    ExceptionOr<Ref<MediaStreamAudioSourceNode>> createMediaStreamSource(MediaStream&);
    143     Ref<MediaStreamAudioDestinationNode> createMediaStreamDestination();
     143    ExceptionOr<Ref<MediaStreamAudioDestinationNode>> createMediaStreamDestination();
    144144#endif
    145     Ref<GainNode> createGain();
    146     Ref<BiquadFilterNode> createBiquadFilter();
    147     Ref<WaveShaperNode> createWaveShaper();
     145    ExceptionOr<Ref<GainNode>> createGain();
     146    ExceptionOr<Ref<BiquadFilterNode>> createBiquadFilter();
     147    ExceptionOr<Ref<WaveShaperNode>> createWaveShaper();
    148148    ExceptionOr<Ref<DelayNode>> createDelay(double maxDelayTime);
    149     Ref<PannerNode> createPanner();
    150     Ref<ConvolverNode> createConvolver();
    151     Ref<DynamicsCompressorNode> createDynamicsCompressor();
    152     Ref<AnalyserNode> createAnalyser();
     149    ExceptionOr<Ref<PannerNode>> createPanner();
     150    ExceptionOr<Ref<ConvolverNode>> createConvolver();
     151    ExceptionOr<Ref<DynamicsCompressorNode>> createDynamicsCompressor();
     152    ExceptionOr<Ref<AnalyserNode>> createAnalyser();
    153153    ExceptionOr<Ref<ScriptProcessorNode>> createScriptProcessor(size_t bufferSize, size_t numberOfInputChannels, size_t numberOfOutputChannels);
    154154    ExceptionOr<Ref<ChannelSplitterNode>> createChannelSplitter(size_t numberOfOutputs);
    155155    ExceptionOr<Ref<ChannelMergerNode>> createChannelMerger(size_t numberOfInputs);
    156     Ref<OscillatorNode> createOscillator();
     156    ExceptionOr<Ref<OscillatorNode>> createOscillator();
    157157    ExceptionOr<Ref<PeriodicWave>> createPeriodicWave(Float32Array& real, Float32Array& imaginary);
    158158
  • trunk/Source/WebCore/Modules/webaudio/AudioContext.idl

    r217919 r244774  
    7070
    7171    // Sources
    72     AudioBufferSourceNode createBufferSource();
     72    [MayThrowException] AudioBufferSourceNode createBufferSource();
    7373
    7474    [Conditional=VIDEO, MayThrowException] MediaElementAudioSourceNode createMediaElementSource(HTMLMediaElement mediaElement);
    7575
    7676    [Conditional=MEDIA_STREAM, MayThrowException] MediaStreamAudioSourceNode createMediaStreamSource(MediaStream mediaStream);
    77     [Conditional=MEDIA_STREAM] MediaStreamAudioDestinationNode createMediaStreamDestination();
     77    [Conditional=MEDIA_STREAM, MayThrowException] MediaStreamAudioDestinationNode createMediaStreamDestination();
    7878
    7979    // Processing nodes
    80     GainNode createGain();
     80    [MayThrowException] GainNode createGain();
    8181    [MayThrowException] DelayNode createDelay(optional unrestricted double maxDelayTime = 1);
    82     BiquadFilterNode createBiquadFilter();
    83     WaveShaperNode createWaveShaper();
    84     PannerNode createPanner();
    85     ConvolverNode createConvolver();
    86     DynamicsCompressorNode createDynamicsCompressor();
    87     AnalyserNode createAnalyser();
     82    [MayThrowException] BiquadFilterNode createBiquadFilter();
     83    [MayThrowException] WaveShaperNode createWaveShaper();
     84    [MayThrowException] PannerNode createPanner();
     85    [MayThrowException] ConvolverNode createConvolver();
     86    [MayThrowException] DynamicsCompressorNode createDynamicsCompressor();
     87    [MayThrowException] AnalyserNode createAnalyser();
    8888    [MayThrowException] ScriptProcessorNode createScriptProcessor(optional unsigned long bufferSize = 0, optional unsigned long numberOfInputChannels = 2, optional unsigned long numberOfOutputChannels = 2);
    89     OscillatorNode createOscillator();
     89    [MayThrowException] OscillatorNode createOscillator();
    9090    [MayThrowException] PeriodicWave createPeriodicWave(Float32Array real, Float32Array imag);
    9191
Note: See TracChangeset for help on using the changeset viewer.