Clean up m_processLock logic in AudioBasicProcessorNode and AudioGainNode
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 1 Feb 2012 03:04:48 +0000 (03:04 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 1 Feb 2012 03:04:48 +0000 (03:04 +0000)
https://bugs.webkit.org/show_bug.cgi?id=76772

Patch by Raymond Liu <raymond.liu@intel.com> on 2012-01-31
Reviewed by Kenneth Russell.

No new tests required.

* webaudio/AudioBasicProcessorNode.cpp:
(WebCore::AudioBasicProcessorNode::process):
(WebCore::AudioBasicProcessorNode::checkNumberOfChannelsForInput):
* webaudio/AudioBasicProcessorNode.h:
* webaudio/AudioGainNode.cpp:
(WebCore::AudioGainNode::process):
(WebCore::AudioGainNode::checkNumberOfChannelsForInput):
* webaudio/AudioGainNode.h:
(AudioGainNode):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@106420 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/webaudio/AudioBasicProcessorNode.cpp
Source/WebCore/webaudio/AudioBasicProcessorNode.h
Source/WebCore/webaudio/AudioGainNode.cpp
Source/WebCore/webaudio/AudioGainNode.h

index 9a807ca..f81018e 100644 (file)
@@ -1,3 +1,22 @@
+2012-01-31  Raymond Liu  <raymond.liu@intel.com>
+
+        Clean up m_processLock logic in AudioBasicProcessorNode and AudioGainNode
+        https://bugs.webkit.org/show_bug.cgi?id=76772
+
+        Reviewed by Kenneth Russell.
+
+        No new tests required.
+
+        * webaudio/AudioBasicProcessorNode.cpp:
+        (WebCore::AudioBasicProcessorNode::process):
+        (WebCore::AudioBasicProcessorNode::checkNumberOfChannelsForInput):
+        * webaudio/AudioBasicProcessorNode.h:
+        * webaudio/AudioGainNode.cpp:
+        (WebCore::AudioGainNode::process):
+        (WebCore::AudioGainNode::checkNumberOfChannelsForInput):
+        * webaudio/AudioGainNode.h:
+        (AudioGainNode):
+
 2012-01-31  Adam Klein  <adamk@chromium.org>
 
         ProcessingInstruction should not be a ContainerNode
index c1d0e5d..1504efb 100644 (file)
@@ -71,24 +71,16 @@ void AudioBasicProcessorNode::process(size_t framesToProcess)
 {
     AudioBus* destinationBus = output(0)->bus();
     
-    // The realtime thread can't block on this lock, so we call tryLock() instead.
-    if (m_processLock.tryLock()) {
-        if (!isInitialized() || !processor())
-            destinationBus->zero();
-        else {
-            AudioBus* sourceBus = input(0)->bus();
-
-            // FIXME: if we take "tail time" into account, then we can avoid calling processor()->process() once the tail dies down.
-            if (!input(0)->isConnected())
-                sourceBus->zero();
-            
-            processor()->process(sourceBus, destinationBus, framesToProcess);  
-        }
-
-        m_processLock.unlock();
-    } else {
-        // Too bad - the tryLock() failed.  We must be in the middle of re-connecting and were already outputting silence anyway...
+    if (!isInitialized() || !processor())
         destinationBus->zero();
+    else {
+        AudioBus* sourceBus = input(0)->bus();
+
+        // FIXME: if we take "tail time" into account, then we can avoid calling processor()->process() once the tail dies down.
+        if (!input(0)->isConnected())
+            sourceBus->zero();
+
+        processor()->process(sourceBus, destinationBus, framesToProcess);  
     }
 }
 
@@ -124,8 +116,6 @@ void AudioBasicProcessorNode::checkNumberOfChannelsForInput(AudioNodeInput* inpu
     
     if (isInitialized() && numberOfChannels != output(0)->numberOfChannels()) {
         // We're already initialized but the channel count has changed.
-        // We need to be careful since we may be actively processing right now, so synchronize with process().
-        MutexLocker locker(m_processLock);
         uninitialize();
     }
     
index 5a555da..36cf2b4 100644 (file)
@@ -57,10 +57,6 @@ public:
 protected:
     AudioProcessor* processor() { return m_processor.get(); }
     OwnPtr<AudioProcessor> m_processor;
-
-private:
-    // This synchronizes live channel count changes which require an uninitialization / re-initialization.
-    mutable Mutex m_processLock;
 };
 
 } // namespace WebCore
index 2129c85..c115432 100644 (file)
@@ -59,31 +59,23 @@ void AudioGainNode::process(size_t framesToProcess)
     AudioBus* outputBus = output(0)->bus();
     ASSERT(outputBus);
 
-    // The realtime thread can't block on this lock, so we call tryLock() instead.
-    if (m_processLock.tryLock()) {
-        if (!isInitialized() || !input(0)->isConnected())
-            outputBus->zero();
-        else {
-            AudioBus* inputBus = input(0)->bus();
-
-            if (gain()->hasTimelineValues()) {
-                // Apply sample-accurate gain scaling for precise envelopes, grain windows, etc.
-                ASSERT(framesToProcess <= m_sampleAccurateGainValues.size());
-                if (framesToProcess <= m_sampleAccurateGainValues.size()) {
-                    float* gainValues = m_sampleAccurateGainValues.data();
-                    gain()->calculateSampleAccurateValues(gainValues, framesToProcess);
-                    outputBus->copyWithSampleAccurateGainValuesFrom(*inputBus, gainValues, framesToProcess);
-                }
-            } else {
-                // Apply the gain with de-zippering into the output bus.
-                outputBus->copyWithGainFrom(*inputBus, &m_lastGain, gain()->value());
+    if (!isInitialized() || !input(0)->isConnected())
+        outputBus->zero();
+    else {
+        AudioBus* inputBus = input(0)->bus();
+
+        if (gain()->hasTimelineValues()) {
+            // Apply sample-accurate gain scaling for precise envelopes, grain windows, etc.
+            ASSERT(framesToProcess <= m_sampleAccurateGainValues.size());
+            if (framesToProcess <= m_sampleAccurateGainValues.size()) {
+                float* gainValues = m_sampleAccurateGainValues.data();
+                gain()->calculateSampleAccurateValues(gainValues, framesToProcess);
+                outputBus->copyWithSampleAccurateGainValuesFrom(*inputBus, gainValues, framesToProcess);
             }
+        } else {
+            // Apply the gain with de-zippering into the output bus.
+            outputBus->copyWithGainFrom(*inputBus, &m_lastGain, gain()->value());
         }
-
-        m_processLock.unlock();
-    } else {
-        // Too bad - the tryLock() failed.  We must be in the middle of re-connecting and were already outputting silence anyway...
-        outputBus->zero();
     }
 }
 
@@ -100,6 +92,8 @@ void AudioGainNode::reset()
 // uninitialize and then re-initialize with the new channel count.
 void AudioGainNode::checkNumberOfChannelsForInput(AudioNodeInput* input)
 {
+    ASSERT(context()->isAudioThread() && context()->isGraphOwner());
+
     ASSERT(input && input == this->input(0));
     if (input != this->input(0))
         return;
@@ -108,8 +102,6 @@ void AudioGainNode::checkNumberOfChannelsForInput(AudioNodeInput* input)
 
     if (isInitialized() && numberOfChannels != output(0)->numberOfChannels()) {
         // We're already initialized but the channel count has changed.
-        // We need to be careful since we may be actively processing right now, so synchronize with process().
-        MutexLocker locker(m_processLock);
         uninitialize();
     }
 
index 415b06b..626ef2c 100644 (file)
@@ -61,10 +61,6 @@ private:
     RefPtr<AudioGain> m_gain;
 
     AudioFloatArray m_sampleAccurateGainValues;
-    
-    // This synchronizes live channel count changes which require an uninitialization / re-initialization.
-    // FIXME: this can go away when we implement optimization for mixing with gain directly in summing junction of AudioNodeInput.
-    mutable Mutex m_processLock;
 };
 
 } // namespace WebCore