Title: [176259] trunk/Source/WebCore
Revision
176259
Author
[email protected]
Date
2014-11-18 08:31:36 -0800 (Tue, 18 Nov 2014)

Log 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
<[email protected]>:
<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):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (176258 => 176259)


--- trunk/Source/WebCore/ChangeLog	2014-11-18 16:09:46 UTC (rev 176258)
+++ trunk/Source/WebCore/ChangeLog	2014-11-18 16:31:36 UTC (rev 176259)
@@ -1,3 +1,34 @@
+2014-11-18  Philippe Normand  <[email protected]>
+
+        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
+        <[email protected]>:
+        <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):
+
 2014-11-18  Commit Queue  <[email protected]>
 
         Unreviewed, rolling out r176218.

Modified: trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp (176258 => 176259)


--- trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp	2014-11-18 16:09:46 UTC (rev 176258)
+++ trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp	2014-11-18 16:31:36 UTC (rev 176259)
@@ -142,12 +142,6 @@
     constructCommon();
 
     m_destinationNode = DefaultAudioDestinationNode::create(this);
-
-    // This sets in motion an asynchronous loading mechanism on another thread.
-    // We can check m_hrtfDatabaseLoader->isLoaded() to find out whether or not it has been fully loaded.
-    // It's not that useful to have a callback function for this since the audio thread automatically starts rendering on the graph
-    // when this has finished (see AudioDestinationNode).
-    m_hrtfDatabaseLoader = HRTFDatabaseLoader::createAndLoadAsynchronouslyIfNecessary(sampleRate());
 }
 
 // Constructor for offline (non-realtime) rendering.
@@ -167,9 +161,6 @@
 {
     constructCommon();
 
-    // FIXME: the passed in sampleRate MUST match the hardware sample-rate since HRTFDatabaseLoader is a singleton.
-    m_hrtfDatabaseLoader = HRTFDatabaseLoader::createAndLoadAsynchronouslyIfNecessary(sampleRate);
-
     // Create a new destination for offline rendering.
     m_renderTarget = AudioBuffer::create(numberOfChannels, numberOfFrames, sampleRate);
     m_destinationNode = OfflineAudioDestinationNode::create(this, m_renderTarget.get());
@@ -288,15 +279,6 @@
     return m_isInitialized;
 }
 
-bool AudioContext::isRunnable() const
-{
-    if (!isInitialized())
-        return false;
-    
-    // Check with the HRTF spatialization system to see if it's finished loading.
-    return m_hrtfDatabaseLoader->isLoaded();
-}
-
 void AudioContext::stopDispatch(void* userData)
 {
     AudioContext* context = reinterpret_cast<AudioContext*>(userData);

Modified: trunk/Source/WebCore/Modules/webaudio/AudioContext.h (176258 => 176259)


--- trunk/Source/WebCore/Modules/webaudio/AudioContext.h	2014-11-18 16:09:46 UTC (rev 176258)
+++ trunk/Source/WebCore/Modules/webaudio/AudioContext.h	2014-11-18 16:31:36 UTC (rev 176259)
@@ -87,11 +87,6 @@
     
     bool isOfflineContext() { return m_isOfflineContext; }
 
-    // Returns true when initialize() was called AND all asynchronous initialization has completed.
-    bool isRunnable() const;
-
-    HRTFDatabaseLoader* hrtfDatabaseLoader() const { return m_hrtfDatabaseLoader.get(); }
-
     // Document notification
     virtual void stop() override;
 
@@ -343,9 +338,6 @@
     
     // Only accessed in the audio thread.
     Vector<AudioNode*> m_deferredFinishDerefList;
-    
-    // HRTF Database loader
-    RefPtr<HRTFDatabaseLoader> m_hrtfDatabaseLoader;
 
     // EventTarget
     virtual void refEventTarget() override { ref(); }

Modified: trunk/Source/WebCore/Modules/webaudio/AudioDestinationNode.cpp (176258 => 176259)


--- trunk/Source/WebCore/Modules/webaudio/AudioDestinationNode.cpp	2014-11-18 16:09:46 UTC (rev 176258)
+++ trunk/Source/WebCore/Modules/webaudio/AudioDestinationNode.cpp	2014-11-18 16:31:36 UTC (rev 176259)
@@ -59,7 +59,7 @@
     
     context()->setAudioThread(currentThread());
     
-    if (!context()->isRunnable()) {
+    if (!context()->isInitialized()) {
         destinationBus->zero();
         return;
     }

Modified: trunk/Source/WebCore/Modules/webaudio/OfflineAudioDestinationNode.cpp (176258 => 176259)


--- trunk/Source/WebCore/Modules/webaudio/OfflineAudioDestinationNode.cpp	2014-11-18 16:09:46 UTC (rev 176258)
+++ trunk/Source/WebCore/Modules/webaudio/OfflineAudioDestinationNode.cpp	2014-11-18 16:31:36 UTC (rev 176259)
@@ -101,7 +101,12 @@
     ASSERT(m_renderBus.get());
     if (!m_renderBus.get())
         return;
-    
+
+    bool isAudioContextInitialized = context()->isInitialized();
+    ASSERT(isAudioContextInitialized);
+    if (!isAudioContextInitialized)
+        return;
+
     bool channelsMatch = m_renderBus->numberOfChannels() == m_renderTarget->numberOfChannels();
     ASSERT(channelsMatch);
     if (!channelsMatch)
@@ -112,15 +117,6 @@
     if (!isRenderBusAllocated)
         return;
         
-    // Synchronize with HRTFDatabaseLoader.
-    // The database must be loaded before we can proceed.
-    HRTFDatabaseLoader* loader = context()->hrtfDatabaseLoader();
-    ASSERT(loader);
-    if (!loader)
-        return;
-    
-    loader->waitForLoaderThreadCompletion();
-        
     // Break up the render target into smaller "render quantize" sized pieces.
     // Render until we're finished.
     size_t framesToProcess = m_renderTarget->length();

Modified: trunk/Source/WebCore/Modules/webaudio/PannerNode.cpp (176258 => 176259)


--- trunk/Source/WebCore/Modules/webaudio/PannerNode.cpp	2014-11-18 16:09:46 UTC (rev 176258)
+++ trunk/Source/WebCore/Modules/webaudio/PannerNode.cpp	2014-11-18 16:31:36 UTC (rev 176259)
@@ -52,6 +52,9 @@
     , m_lastGain(-1.0)
     , m_connectionCount(0)
 {
+    // Load the HRTF database asynchronously so we don't block the _javascript_ thread while creating the HRTF database.
+    m_hrtfDatabaseLoader = HRTFDatabaseLoader::createAndLoadAsynchronouslyIfNecessary(context->sampleRate());
+
     addInput(std::make_unique<AudioNodeInput>(this));
     addOutput(std::make_unique<AudioNodeOutput>(this, 2));
 
@@ -101,12 +104,21 @@
     }
 
     AudioBus* source = input(0)->bus();
-
     if (!source) {
         destination->zero();
         return;
     }
 
+    // HRTFDatabase should be loaded before proceeding for offline audio context when panningModel() is "HRTF".
+    if (panningModel() == "HRTF" && !m_hrtfDatabaseLoader->isLoaded()) {
+        if (context()->isOfflineContext())
+            m_hrtfDatabaseLoader->waitForLoaderThreadCompletion();
+        else {
+            destination->zero();
+            return;
+        }
+    }
+
     // The audio thread can't block on this lock, so we use std::try_to_lock instead.
     std::unique_lock<std::mutex> lock(m_pannerMutex, std::try_to_lock);
     if (!lock.owns_lock()) {
@@ -144,7 +156,7 @@
     if (isInitialized())
         return;
 
-    m_panner = Panner::create(m_panningModel, sampleRate(), context()->hrtfDatabaseLoader());
+    m_panner = Panner::create(m_panningModel, sampleRate(), m_hrtfDatabaseLoader.get());
 
     AudioNode::initialize();
 }
@@ -199,7 +211,7 @@
             // This synchronizes with process().
             std::lock_guard<std::mutex> lock(m_pannerMutex);
 
-            m_panner = Panner::create(model, sampleRate(), context()->hrtfDatabaseLoader());
+            m_panner = Panner::create(model, sampleRate(), m_hrtfDatabaseLoader.get());
             m_panningModel = model;
         }
         break;

Modified: trunk/Source/WebCore/Modules/webaudio/PannerNode.h (176258 => 176259)


--- trunk/Source/WebCore/Modules/webaudio/PannerNode.h	2014-11-18 16:09:46 UTC (rev 176258)
+++ trunk/Source/WebCore/Modules/webaudio/PannerNode.h	2014-11-18 16:31:36 UTC (rev 176259)
@@ -32,6 +32,7 @@
 #include "Cone.h"
 #include "Distance.h"
 #include "FloatPoint3D.h"
+#include "HRTFDatabaseLoader.h"
 #include "Panner.h"
 #include <memory>
 #include <mutex>
@@ -154,6 +155,9 @@
     ConeEffect m_coneEffect;
     float m_lastGain;
 
+    // HRTF Database loader
+    RefPtr<HRTFDatabaseLoader> m_hrtfDatabaseLoader;
+
     unsigned m_connectionCount;
 
     // Synchronize process() and setPanningModel() which can change the panner.

Modified: trunk/Source/WebCore/Modules/webaudio/RealtimeAnalyser.cpp (176258 => 176259)


--- trunk/Source/WebCore/Modules/webaudio/RealtimeAnalyser.cpp	2014-11-18 16:09:46 UTC (rev 176258)
+++ trunk/Source/WebCore/Modules/webaudio/RealtimeAnalyser.cpp	2014-11-18 16:31:36 UTC (rev 176259)
@@ -30,7 +30,6 @@
 
 #include "AudioBus.h"
 #include "AudioUtilities.h"
-#include "FFTFrame.h"
 #include "VectorMath.h"
 #include <algorithm>
 #include <complex>

Modified: trunk/Source/WebCore/Modules/webaudio/RealtimeAnalyser.h (176258 => 176259)


--- trunk/Source/WebCore/Modules/webaudio/RealtimeAnalyser.h	2014-11-18 16:09:46 UTC (rev 176258)
+++ trunk/Source/WebCore/Modules/webaudio/RealtimeAnalyser.h	2014-11-18 16:31:36 UTC (rev 176259)
@@ -26,6 +26,7 @@
 #define RealtimeAnalyser_h
 
 #include "AudioArray.h"
+#include "FFTFrame.h"
 #include <memory>
 #include <runtime/Float32Array.h>
 #include <runtime/Uint8Array.h>
@@ -35,7 +36,6 @@
 namespace WebCore {
 
 class AudioBus;
-class FFTFrame;
 
 class RealtimeAnalyser {
     WTF_MAKE_NONCOPYABLE(RealtimeAnalyser);

Modified: trunk/Source/WebCore/platform/audio/HRTFDatabaseLoader.cpp (176258 => 176259)


--- trunk/Source/WebCore/platform/audio/HRTFDatabaseLoader.cpp	2014-11-18 16:09:46 UTC (rev 176258)
+++ trunk/Source/WebCore/platform/audio/HRTFDatabaseLoader.cpp	2014-11-18 16:31:36 UTC (rev 176259)
@@ -49,9 +49,7 @@
 {
     ASSERT(isMainThread());
 
-    RefPtr<HRTFDatabaseLoader> loader;
-    
-    loader = loaderMap().get(sampleRate);
+    RefPtr<HRTFDatabaseLoader> loader = loaderMap().get(sampleRate);
     if (loader) {
         ASSERT(sampleRate == loader->databaseSampleRate());
         return loader;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to