• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
25 #ifndef AudioNodeInput_h
26 #define AudioNodeInput_h
27 
28 #include "platform/audio/AudioBus.h"
29 #include "modules/webaudio/AudioNode.h"
30 #include "modules/webaudio/AudioSummingJunction.h"
31 #include "wtf/HashSet.h"
32 
33 namespace blink {
34 
35 class AudioNode;
36 class AudioNodeOutput;
37 
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.
41 
42 class AudioNodeInput FINAL : public AudioSummingJunction {
43 public:
44     static AudioNodeInput* create(AudioNode&);
45 
46     // AudioSummingJunction
47     virtual void trace(Visitor*) OVERRIDE;
48     virtual void didUpdate() OVERRIDE;
49 
50     // Can be called from any thread.
node()51     AudioNode& node() const { return *m_node; }
52 
53     // Must be called with the context's graph lock.
54     void connect(AudioNodeOutput&);
55     void disconnect(AudioNodeOutput&);
56 
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&);
62 
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);
69 
70     // bus() contains the rendered audio after pull() has been called for each time quantum.
71     // Called from context's audio thread.
72     AudioBus* bus();
73 
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();
77 
78     // The number of channels of the connection with the largest number of channels.
79     unsigned numberOfChannels() const;
80 
81 private:
82     explicit AudioNodeInput(AudioNode&);
83 
84     Member<AudioNode> m_node;
85 
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;
93 
94     // Called from context's audio thread.
95     AudioBus* internalSummingBus();
96     void sumAllConnections(AudioBus* summingBus, size_t framesToProcess);
97 
98     RefPtr<AudioBus> m_internalSummingBus;
99 };
100 
101 } // namespace blink
102 
103 #endif // AudioNodeInput_h
104