crogers@google.com | 7c44211 | 2010-10-27 01:59:08 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010, Google Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY |
| 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 15 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 16 | * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 17 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 18 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 19 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
| 20 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 21 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 22 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 23 | */ |
| 24 | |
commit-queue@webkit.org | 553e8d3 | 2016-11-12 08:57:21 +0000 | [diff] [blame] | 25 | #pragma once |
crogers@google.com | 7c44211 | 2010-10-27 01:59:08 +0000 | [diff] [blame] | 26 | |
| 27 | #include "AudioBus.h" |
| 28 | #include "AudioNode.h" |
crogers@google.com | caebe6f | 2012-05-15 19:56:51 +0000 | [diff] [blame] | 29 | #include "AudioSummingJunction.h" |
crogers@google.com | 7c44211 | 2010-10-27 01:59:08 +0000 | [diff] [blame] | 30 | #include <wtf/HashSet.h> |
crogers@google.com | 7c44211 | 2010-10-27 01:59:08 +0000 | [diff] [blame] | 31 | |
| 32 | namespace WebCore { |
| 33 | |
| 34 | class AudioNode; |
| 35 | class AudioNodeOutput; |
| 36 | |
| 37 | // An AudioNodeInput represents an input to an AudioNode and can be connected from one or more AudioNodeOutputs. |
| 38 | // In the case of multiple connections, the input will act as a unity-gain summing junction, mixing all the outputs. |
| 39 | // The number of channels of the input's bus is the maximum of the number of channels of all its connections. |
| 40 | |
crogers@google.com | caebe6f | 2012-05-15 19:56:51 +0000 | [diff] [blame] | 41 | class AudioNodeInput : public AudioSummingJunction { |
crogers@google.com | 7c44211 | 2010-10-27 01:59:08 +0000 | [diff] [blame] | 42 | public: |
commit-queue@webkit.org | 0ae74fb | 2012-07-28 01:23:58 +0000 | [diff] [blame] | 43 | explicit AudioNodeInput(AudioNode*); |
crogers@google.com | 7c44211 | 2010-10-27 01:59:08 +0000 | [diff] [blame] | 44 | |
crogers@google.com | caebe6f | 2012-05-15 19:56:51 +0000 | [diff] [blame] | 45 | // AudioSummingJunction |
darin@apple.com | 11ff47c | 2016-03-04 16:47:55 +0000 | [diff] [blame] | 46 | bool canUpdateState() override { return !node()->isMarkedForDeletion(); } |
| 47 | void didUpdate() override; |
crogers@google.com | caebe6f | 2012-05-15 19:56:51 +0000 | [diff] [blame] | 48 | |
crogers@google.com | 7c44211 | 2010-10-27 01:59:08 +0000 | [diff] [blame] | 49 | // Can be called from any thread. |
| 50 | AudioNode* node() const { return m_node; } |
crogers@google.com | 7c44211 | 2010-10-27 01:59:08 +0000 | [diff] [blame] | 51 | |
| 52 | // Must be called with the context's graph lock. |
| 53 | void connect(AudioNodeOutput*); |
| 54 | void disconnect(AudioNodeOutput*); |
| 55 | |
| 56 | // disable() will take the output out of the active connections list and set aside in a disabled list. |
| 57 | // enable() will put the output back into the active connections list. |
| 58 | // Must be called with the context's graph lock. |
| 59 | void enable(AudioNodeOutput*); |
| 60 | void disable(AudioNodeOutput*); |
| 61 | |
| 62 | // pull() processes all of the AudioNodes connected to us. |
| 63 | // In the case of multiple connections it sums the result into an internal summing bus. |
| 64 | // In the single connection case, it allows in-place processing where possible using inPlaceBus. |
| 65 | // It returns the bus which it rendered into, returning inPlaceBus if in-place processing was performed. |
| 66 | // Called from context's audio thread. |
| 67 | AudioBus* pull(AudioBus* inPlaceBus, size_t framesToProcess); |
| 68 | |
| 69 | // bus() contains the rendered audio after pull() has been called for each time quantum. |
| 70 | // Called from context's audio thread. |
| 71 | AudioBus* bus(); |
| 72 | |
commit-queue@webkit.org | 2c1debb | 2012-02-01 03:23:12 +0000 | [diff] [blame] | 73 | // updateInternalBus() updates m_internalSummingBus appropriately for the number of channels. |
| 74 | // This must be called when we own the context's graph lock in the audio thread at the very start or end of the render quantum. |
| 75 | void updateInternalBus(); |
| 76 | |
crogers@google.com | 7c44211 | 2010-10-27 01:59:08 +0000 | [diff] [blame] | 77 | // The number of channels of the connection with the largest number of channels. |
| 78 | unsigned numberOfChannels() const; |
| 79 | |
| 80 | private: |
| 81 | AudioNode* m_node; |
| 82 | |
crogers@google.com | 7c44211 | 2010-10-27 01:59:08 +0000 | [diff] [blame] | 83 | // m_disabledOutputs contains the AudioNodeOutputs which are disabled (will not be processed) by the audio graph rendering. |
| 84 | // But, from JavaScript's perspective, these outputs are still connected to us. |
| 85 | // Generally, these represent disabled connections from "notes" which have finished playing but are not yet garbage collected. |
| 86 | HashSet<AudioNodeOutput*> m_disabledOutputs; |
| 87 | |
| 88 | // Called from context's audio thread. |
| 89 | AudioBus* internalSummingBus(); |
| 90 | void sumAllConnections(AudioBus* summingBus, size_t framesToProcess); |
| 91 | |
xingnan.wang@intel.com | dc26202 | 2013-05-08 23:38:46 +0000 | [diff] [blame] | 92 | RefPtr<AudioBus> m_internalSummingBus; |
crogers@google.com | 7c44211 | 2010-10-27 01:59:08 +0000 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | } // namespace WebCore |