2 * Copyright (C) 2010, Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
25 #ifndef AudioNodeInput_h
26 #define AudioNodeInput_h
28 #include "platform/audio/AudioBus.h"
29 #include "modules/webaudio/AudioNode.h"
30 #include "modules/webaudio/AudioSummingJunction.h"
31 #include "wtf/HashSet.h"
36 class AudioNodeOutput;
38 // An AudioNodeInput represents an input to an AudioNode and can be connected from one or more AudioNodeOutputs.
39 // In the case of multiple connections, the input will act as a unity-gain summing junction, mixing all the outputs.
40 // The number of channels of the input's bus is the maximum of the number of channels of all its connections.
42 class AudioNodeInput final : public AudioSummingJunction {
44 static AudioNodeInput* create(AudioNode&);
46 // AudioSummingJunction
47 virtual void trace(Visitor*) override;
48 virtual void didUpdate() override;
50 // Can be called from any thread.
51 AudioNode& node() const { return *m_node; }
53 // Must be called with the context's graph lock.
54 void connect(AudioNodeOutput&);
55 void disconnect(AudioNodeOutput&);
57 // disable() will take the output out of the active connections list and set aside in a disabled list.
58 // enable() will put the output back into the active connections list.
59 // Must be called with the context's graph lock.
60 void enable(AudioNodeOutput&);
61 void disable(AudioNodeOutput&);
63 // pull() processes all of the AudioNodes connected to us.
64 // In the case of multiple connections it sums the result into an internal summing bus.
65 // In the single connection case, it allows in-place processing where possible using inPlaceBus.
66 // It returns the bus which it rendered into, returning inPlaceBus if in-place processing was performed.
67 // Called from context's audio thread.
68 AudioBus* pull(AudioBus* inPlaceBus, size_t framesToProcess);
70 // bus() contains the rendered audio after pull() has been called for each time quantum.
71 // Called from context's audio thread.
74 // updateInternalBus() updates m_internalSummingBus appropriately for the number of channels.
75 // 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.
76 void updateInternalBus();
78 // The number of channels of the connection with the largest number of channels.
79 unsigned numberOfChannels() const;
82 explicit AudioNodeInput(AudioNode&);
84 Member<AudioNode> m_node;
86 // m_disabledOutputs contains the AudioNodeOutputs which are disabled (will not be processed) by the audio graph rendering.
87 // But, from JavaScript's perspective, these outputs are still connected to us.
88 // Generally, these represent disabled connections from "notes" which have finished playing but are not yet garbage collected.
89 // Oilpan: Since items are added to the hash set by the audio thread (not registered to Oilpan),
90 // we cannot use a HeapHashSet.
91 GC_PLUGIN_IGNORE("http://crbug.com/404527")
92 HashSet<AudioNodeOutput*> m_disabledOutputs;
94 // Called from context's audio thread.
95 AudioBus* internalSummingBus();
96 void sumAllConnections(AudioBus* summingBus, size_t framesToProcess);
98 RefPtr<AudioBus> m_internalSummingBus;
103 #endif // AudioNodeInput_h