Skip to content
Permalink
Browse files
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):

Canonical link: https://commits.webkit.org/156680@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@176259 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
philn committed Nov 18, 2014
1 parent adde334 commit efeba041ad819b9f9c7a81749edb5c44b1bdacd7
@@ -1,3 +1,34 @@
2014-11-18 Philippe Normand <pnormand@igalia.com>

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):

2014-11-18 Commit Queue <commit-queue@webkit.org>

Unreviewed, rolling out r176218.
@@ -142,12 +142,6 @@ AudioContext::AudioContext(Document& document)
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 @@ AudioContext::AudioContext(Document& document, unsigned numberOfChannels, size_t
{
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 @@ bool AudioContext::isInitialized() const
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);
@@ -87,11 +87,6 @@ class AudioContext : public ActiveDOMObject, public ThreadSafeRefCounted<AudioCo

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 @@ class AudioContext : public ActiveDOMObject, public ThreadSafeRefCounted<AudioCo

// Only accessed in the audio thread.
Vector<AudioNode*> m_deferredFinishDerefList;

// HRTF Database loader
RefPtr<HRTFDatabaseLoader> m_hrtfDatabaseLoader;

// EventTarget
virtual void refEventTarget() override { ref(); }
@@ -59,7 +59,7 @@ void AudioDestinationNode::render(AudioBus* sourceBus, AudioBus* destinationBus,

context()->setAudioThread(currentThread());

if (!context()->isRunnable()) {
if (!context()->isInitialized()) {
destinationBus->zero();
return;
}
@@ -101,7 +101,12 @@ void OfflineAudioDestinationNode::offlineRender()
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 @@ void OfflineAudioDestinationNode::offlineRender()
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();
@@ -52,6 +52,9 @@ PannerNode::PannerNode(AudioContext* context, float sampleRate)
, 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 @@ void PannerNode::process(size_t framesToProcess)
}

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 @@ void PannerNode::initialize()
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 @@ bool PannerNode::setPanningModel(unsigned model)
// 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;
@@ -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 @@ class PannerNode : public AudioNode {
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.
@@ -30,7 +30,6 @@

#include "AudioBus.h"
#include "AudioUtilities.h"
#include "FFTFrame.h"
#include "VectorMath.h"
#include <algorithm>
#include <complex>
@@ -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);
@@ -49,9 +49,7 @@ PassRefPtr<HRTFDatabaseLoader> HRTFDatabaseLoader::createAndLoadAsynchronouslyIf
{
ASSERT(isMainThread());

RefPtr<HRTFDatabaseLoader> loader;

loader = loaderMap().get(sampleRate);
RefPtr<HRTFDatabaseLoader> loader = loaderMap().get(sampleRate);
if (loader) {
ASSERT(sampleRate == loader->databaseSampleRate());
return loader;

0 comments on commit efeba04

Please sign in to comment.