diff options
Diffstat (limited to 'WebCore/webaudio/AudioContext.cpp')
-rw-r--r-- | WebCore/webaudio/AudioContext.cpp | 46 |
1 files changed, 24 insertions, 22 deletions
diff --git a/WebCore/webaudio/AudioContext.cpp b/WebCore/webaudio/AudioContext.cpp index 6ca8ee1..f971e6a 100644 --- a/WebCore/webaudio/AudioContext.cpp +++ b/WebCore/webaudio/AudioContext.cpp @@ -1,29 +1,25 @@ /* - * Copyright (C) 2010 Google Inc. All rights reserved. + * Copyright (C) 2010, Google Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. * - * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "config.h" @@ -58,7 +54,9 @@ // FIXME: check the proper way to reference an undefined thread ID const int UndefinedThreadIdentifier = 0xffffffff; - + +const unsigned MaxNodesToDeletePerQuantum = 10; + namespace WebCore { PassRefPtr<CachedAudio> AudioContext::createAudioRequest(const String &url, bool mixToMono) @@ -102,10 +100,10 @@ AudioContext::AudioContext(Document* document) m_temporaryStereoBus = adoptPtr(new AudioBus(2, AudioNode::ProcessingSizeInFrames)); // This sets in motion an asynchronous loading mechanism on another thread. - // We can check hrtfDatabaseLoader()->isLoaded() to find out whether or not it has been fully loaded. + // 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). - hrtfDatabaseLoader()->loadAsynchronously(sampleRate()); + m_hrtfDatabaseLoader = HRTFDatabaseLoader::createAndLoadAsynchronouslyIfNecessary(sampleRate()); } AudioContext::~AudioContext() @@ -172,7 +170,7 @@ bool AudioContext::isRunnable() const return false; // Check with the HRTF spatialization system to see if it's finished loading. - return hrtfDatabaseLoader()->isLoaded(); + return m_hrtfDatabaseLoader->isLoaded(); } void AudioContext::stop() @@ -346,10 +344,9 @@ void AudioContext::lock(bool& mustReleaseLock) } else { // Acquire the lock. m_contextGraphMutex.lock(); + m_graphOwnerThread = thisThread; mustReleaseLock = true; } - - m_graphOwnerThread = thisThread; } bool AudioContext::tryLock(bool& mustReleaseLock) @@ -412,7 +409,7 @@ void AudioContext::addDeferredFinishDeref(AudioNode* node, AudioNode::RefType re void AudioContext::handlePostRenderTasks() { ASSERT(isAudioThread()); - + // Must use a tryLock() here too. Don't worry, the lock will very rarely be contended and this method is called frequently. // The worst that can happen is that there will be some nodes which will take slightly longer than usual to be deleted or removed // from the render graph (in which case they'll render silence). @@ -434,7 +431,7 @@ void AudioContext::handlePostRenderTasks() void AudioContext::handleDeferredFinishDerefs() { - ASSERT(isAudioThread()); + ASSERT(isAudioThread() && isGraphOwner()); for (unsigned i = 0; i < m_deferredFinishDerefList.size(); ++i) { AudioNode* node = m_deferredFinishDerefList[i].m_node; AudioNode::RefType refType = m_deferredFinishDerefList[i].m_refType; @@ -455,10 +452,15 @@ void AudioContext::deleteMarkedNodes() ASSERT(isGraphOwner() || isAudioThreadFinished()); // Note: deleting an AudioNode can cause m_nodesToDelete to grow. + size_t nodesDeleted = 0; while (size_t n = m_nodesToDelete.size()) { AudioNode* node = m_nodesToDelete[n - 1]; m_nodesToDelete.removeLast(); delete node; + + // Don't delete too many nodes per render quantum since we don't want to do too much work in the realtime audio thread. + if (++nodesDeleted > MaxNodesToDeletePerQuantum) + break; } } |