blob: 3e8cc40ede516432524ac3fc12e47338769c19a1 [file] [log] [blame]
crogers@google.com7c442112010-10-27 01:59:08 +00001/*
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.org553e8d32016-11-12 08:57:21 +000025#pragma once
crogers@google.com7c442112010-10-27 01:59:08 +000026
27#include "AudioBus.h"
28#include "AudioNode.h"
crogers@google.comcaebe6f2012-05-15 19:56:51 +000029#include "AudioSummingJunction.h"
crogers@google.com7c442112010-10-27 01:59:08 +000030#include <wtf/HashSet.h>
crogers@google.com7c442112010-10-27 01:59:08 +000031
32namespace WebCore {
33
34class AudioNode;
35class 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.comcaebe6f2012-05-15 19:56:51 +000041class AudioNodeInput : public AudioSummingJunction {
crogers@google.com7c442112010-10-27 01:59:08 +000042public:
commit-queue@webkit.org0ae74fb2012-07-28 01:23:58 +000043 explicit AudioNodeInput(AudioNode*);
crogers@google.com7c442112010-10-27 01:59:08 +000044
crogers@google.comcaebe6f2012-05-15 19:56:51 +000045 // AudioSummingJunction
darin@apple.com11ff47c2016-03-04 16:47:55 +000046 bool canUpdateState() override { return !node()->isMarkedForDeletion(); }
47 void didUpdate() override;
crogers@google.comcaebe6f2012-05-15 19:56:51 +000048
crogers@google.com7c442112010-10-27 01:59:08 +000049 // Can be called from any thread.
50 AudioNode* node() const { return m_node; }
crogers@google.com7c442112010-10-27 01:59:08 +000051
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.org2c1debb2012-02-01 03:23:12 +000073 // 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.com7c442112010-10-27 01:59:08 +000077 // The number of channels of the connection with the largest number of channels.
78 unsigned numberOfChannels() const;
79
80private:
81 AudioNode* m_node;
82
crogers@google.com7c442112010-10-27 01:59:08 +000083 // 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.comdc262022013-05-08 23:38:46 +000092 RefPtr<AudioBus> m_internalSummingBus;
crogers@google.com7c442112010-10-27 01:59:08 +000093};
94
95} // namespace WebCore