Changeset 176259 in webkit


Ignore:
Timestamp:
Nov 18, 2014 8:31:36 AM (9 years ago)
Author:
Philippe Normand
Message:

HRTFDatabaseLoader is not an absolute condition to run audioContext
https://bugs.webkit.org/show_bug.cgi?id=138829

Reviewed by Jer Noble.

This patch is a port of the following Blink revision by
<keonho07.kim@samsung.com>:
<https://src.chromium.org/viewvc/blink?revision=167887&view=revision>

  • Modules/webaudio/AudioContext.cpp:

(WebCore::AudioContext::AudioContext):
(WebCore::AudioContext::isRunnable): Deleted.

  • Modules/webaudio/AudioContext.h:

(WebCore::AudioContext::hrtfDatabaseLoader): Deleted.

  • Modules/webaudio/AudioDestinationNode.cpp:

(WebCore::AudioDestinationNode::render):

  • Modules/webaudio/OfflineAudioDestinationNode.cpp:

(WebCore::OfflineAudioDestinationNode::offlineRender):

  • Modules/webaudio/PannerNode.cpp:

(WebCore::PannerNode::PannerNode):
(WebCore::PannerNode::process):
(WebCore::PannerNode::initialize):
(WebCore::PannerNode::setPanningModel):

  • Modules/webaudio/PannerNode.h:
  • Modules/webaudio/RealtimeAnalyser.cpp:
  • Modules/webaudio/RealtimeAnalyser.h:
  • platform/audio/HRTFDatabaseLoader.cpp:

(WebCore::HRTFDatabaseLoader::createAndLoadAsynchronouslyIfNecessary):

Location:
trunk/Source/WebCore
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r176258 r176259  
     12014-11-18  Philippe Normand  <pnormand@igalia.com>
     2
     3        HRTFDatabaseLoader is not an absolute condition to run audioContext
     4        https://bugs.webkit.org/show_bug.cgi?id=138829
     5
     6        Reviewed by Jer Noble.
     7
     8        This patch is a port of the following Blink revision by
     9        <keonho07.kim@samsung.com>:
     10        <https://src.chromium.org/viewvc/blink?revision=167887&view=revision>
     11
     12        * Modules/webaudio/AudioContext.cpp:
     13        (WebCore::AudioContext::AudioContext):
     14        (WebCore::AudioContext::isRunnable): Deleted.
     15        * Modules/webaudio/AudioContext.h:
     16        (WebCore::AudioContext::hrtfDatabaseLoader): Deleted.
     17        * Modules/webaudio/AudioDestinationNode.cpp:
     18        (WebCore::AudioDestinationNode::render):
     19        * Modules/webaudio/OfflineAudioDestinationNode.cpp:
     20        (WebCore::OfflineAudioDestinationNode::offlineRender):
     21        * Modules/webaudio/PannerNode.cpp:
     22        (WebCore::PannerNode::PannerNode):
     23        (WebCore::PannerNode::process):
     24        (WebCore::PannerNode::initialize):
     25        (WebCore::PannerNode::setPanningModel):
     26        * Modules/webaudio/PannerNode.h:
     27        * Modules/webaudio/RealtimeAnalyser.cpp:
     28        * Modules/webaudio/RealtimeAnalyser.h:
     29        * platform/audio/HRTFDatabaseLoader.cpp:
     30        (WebCore::HRTFDatabaseLoader::createAndLoadAsynchronouslyIfNecessary):
     31
    1322014-11-18  Commit Queue  <commit-queue@webkit.org>
    233
  • trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp

    r174089 r176259  
    143143
    144144    m_destinationNode = DefaultAudioDestinationNode::create(this);
    145 
    146     // This sets in motion an asynchronous loading mechanism on another thread.
    147     // We can check m_hrtfDatabaseLoader->isLoaded() to find out whether or not it has been fully loaded.
    148     // It's not that useful to have a callback function for this since the audio thread automatically starts rendering on the graph
    149     // when this has finished (see AudioDestinationNode).
    150     m_hrtfDatabaseLoader = HRTFDatabaseLoader::createAndLoadAsynchronouslyIfNecessary(sampleRate());
    151145}
    152146
     
    168162    constructCommon();
    169163
    170     // FIXME: the passed in sampleRate MUST match the hardware sample-rate since HRTFDatabaseLoader is a singleton.
    171     m_hrtfDatabaseLoader = HRTFDatabaseLoader::createAndLoadAsynchronouslyIfNecessary(sampleRate);
    172 
    173164    // Create a new destination for offline rendering.
    174165    m_renderTarget = AudioBuffer::create(numberOfChannels, numberOfFrames, sampleRate);
     
    289280}
    290281
    291 bool AudioContext::isRunnable() const
    292 {
    293     if (!isInitialized())
    294         return false;
    295    
    296     // Check with the HRTF spatialization system to see if it's finished loading.
    297     return m_hrtfDatabaseLoader->isLoaded();
    298 }
    299 
    300282void AudioContext::stopDispatch(void* userData)
    301283{
  • trunk/Source/WebCore/Modules/webaudio/AudioContext.h

    r162777 r176259  
    8787   
    8888    bool isOfflineContext() { return m_isOfflineContext; }
    89 
    90     // Returns true when initialize() was called AND all asynchronous initialization has completed.
    91     bool isRunnable() const;
    92 
    93     HRTFDatabaseLoader* hrtfDatabaseLoader() const { return m_hrtfDatabaseLoader.get(); }
    9489
    9590    // Document notification
     
    344339    // Only accessed in the audio thread.
    345340    Vector<AudioNode*> m_deferredFinishDerefList;
    346    
    347     // HRTF Database loader
    348     RefPtr<HRTFDatabaseLoader> m_hrtfDatabaseLoader;
    349341
    350342    // EventTarget
  • trunk/Source/WebCore/Modules/webaudio/AudioDestinationNode.cpp

    r162368 r176259  
    6060    context()->setAudioThread(currentThread());
    6161   
    62     if (!context()->isRunnable()) {
     62    if (!context()->isInitialized()) {
    6363        destinationBus->zero();
    6464        return;
  • trunk/Source/WebCore/Modules/webaudio/OfflineAudioDestinationNode.cpp

    r157971 r176259  
    102102    if (!m_renderBus.get())
    103103        return;
    104    
     104
     105    bool isAudioContextInitialized = context()->isInitialized();
     106    ASSERT(isAudioContextInitialized);
     107    if (!isAudioContextInitialized)
     108        return;
     109
    105110    bool channelsMatch = m_renderBus->numberOfChannels() == m_renderTarget->numberOfChannels();
    106111    ASSERT(channelsMatch);
     
    112117    if (!isRenderBusAllocated)
    113118        return;
    114        
    115     // Synchronize with HRTFDatabaseLoader.
    116     // The database must be loaded before we can proceed.
    117     HRTFDatabaseLoader* loader = context()->hrtfDatabaseLoader();
    118     ASSERT(loader);
    119     if (!loader)
    120         return;
    121    
    122     loader->waitForLoaderThreadCompletion();
    123119       
    124120    // Break up the render target into smaller "render quantize" sized pieces.
  • trunk/Source/WebCore/Modules/webaudio/PannerNode.cpp

    r163568 r176259  
    5353    , m_connectionCount(0)
    5454{
     55    // Load the HRTF database asynchronously so we don't block the Javascript thread while creating the HRTF database.
     56    m_hrtfDatabaseLoader = HRTFDatabaseLoader::createAndLoadAsynchronouslyIfNecessary(context->sampleRate());
     57
    5558    addInput(std::make_unique<AudioNodeInput>(this));
    5659    addOutput(std::make_unique<AudioNodeOutput>(this, 2));
     
    102105
    103106    AudioBus* source = input(0)->bus();
    104 
    105107    if (!source) {
    106108        destination->zero();
    107109        return;
     110    }
     111
     112    // HRTFDatabase should be loaded before proceeding for offline audio context when panningModel() is "HRTF".
     113    if (panningModel() == "HRTF" && !m_hrtfDatabaseLoader->isLoaded()) {
     114        if (context()->isOfflineContext())
     115            m_hrtfDatabaseLoader->waitForLoaderThreadCompletion();
     116        else {
     117            destination->zero();
     118            return;
     119        }
    108120    }
    109121
     
    145157        return;
    146158
    147     m_panner = Panner::create(m_panningModel, sampleRate(), context()->hrtfDatabaseLoader());
     159    m_panner = Panner::create(m_panningModel, sampleRate(), m_hrtfDatabaseLoader.get());
    148160
    149161    AudioNode::initialize();
     
    200212            std::lock_guard<std::mutex> lock(m_pannerMutex);
    201213
    202             m_panner = Panner::create(model, sampleRate(), context()->hrtfDatabaseLoader());
     214            m_panner = Panner::create(model, sampleRate(), m_hrtfDatabaseLoader.get());
    203215            m_panningModel = model;
    204216        }
  • trunk/Source/WebCore/Modules/webaudio/PannerNode.h

    r162368 r176259  
    3333#include "Distance.h"
    3434#include "FloatPoint3D.h"
     35#include "HRTFDatabaseLoader.h"
    3536#include "Panner.h"
    3637#include <memory>
     
    155156    float m_lastGain;
    156157
     158    // HRTF Database loader
     159    RefPtr<HRTFDatabaseLoader> m_hrtfDatabaseLoader;
     160
    157161    unsigned m_connectionCount;
    158162
  • trunk/Source/WebCore/Modules/webaudio/RealtimeAnalyser.cpp

    r172816 r176259  
    3131#include "AudioBus.h"
    3232#include "AudioUtilities.h"
    33 #include "FFTFrame.h"
    3433#include "VectorMath.h"
    3534#include <algorithm>
  • trunk/Source/WebCore/Modules/webaudio/RealtimeAnalyser.h

    r162368 r176259  
    2727
    2828#include "AudioArray.h"
     29#include "FFTFrame.h"
    2930#include <memory>
    3031#include <runtime/Float32Array.h>
     
    3637
    3738class AudioBus;
    38 class FFTFrame;
    3939
    4040class RealtimeAnalyser {
  • trunk/Source/WebCore/platform/audio/HRTFDatabaseLoader.cpp

    r165676 r176259  
    5050    ASSERT(isMainThread());
    5151
    52     RefPtr<HRTFDatabaseLoader> loader;
    53    
    54     loader = loaderMap().get(sampleRate);
     52    RefPtr<HRTFDatabaseLoader> loader = loaderMap().get(sampleRate);
    5553    if (loader) {
    5654        ASSERT(sampleRate == loader->databaseSampleRate());
Note: See TracChangeset for help on using the changeset viewer.