Home | History | Annotate | Download | only in webaudio
      1 /*
      2  * Copyright (C) 2012, 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 AudioSummingJunction_h
     26 #define AudioSummingJunction_h
     27 
     28 #include "platform/audio/AudioBus.h"
     29 #include "platform/heap/Handle.h"
     30 #include "wtf/HashSet.h"
     31 #include "wtf/Vector.h"
     32 
     33 namespace blink {
     34 
     35 class AudioContext;
     36 class AudioNodeOutput;
     37 
     38 // An AudioSummingJunction represents a point where zero, one, or more AudioNodeOutputs connect.
     39 
     40 class AudioSummingJunction : public GarbageCollectedFinalized<AudioSummingJunction> {
     41 public:
     42     virtual ~AudioSummingJunction();
     43     virtual void trace(Visitor*);
     44     void dispose();
     45 
     46     // Can be called from any thread.
     47     AudioContext* context() { return m_context.get(); }
     48 
     49     // This must be called whenever we modify m_outputs.
     50     void changedOutputs();
     51 
     52     // This copies m_outputs to m_renderingOutputs. Please see comments for these lists below.
     53     // 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.
     54     void updateRenderingState();
     55 
     56     // Rendering code accesses its version of the current connections here.
     57     unsigned numberOfRenderingConnections() const { return m_renderingOutputs.size(); }
     58     AudioNodeOutput* renderingOutput(unsigned i) { return m_renderingOutputs[i]; }
     59     bool isConnected() const { return numberOfRenderingConnections() > 0; }
     60 
     61     virtual void didUpdate() = 0;
     62 
     63 protected:
     64     explicit AudioSummingJunction(AudioContext*);
     65 
     66     Member<AudioContext> m_context;
     67 
     68     // m_outputs contains the AudioNodeOutputs representing current connections which are not disabled.
     69     // The rendering code should never use this directly, but instead uses m_renderingOutputs.
     70     // Oilpan: Since items are added to the hash set by the audio thread (not registered to Oilpan),
     71     // we cannot use a HeapHashSet.
     72     GC_PLUGIN_IGNORE("http://crbug.com/404527")
     73     HashSet<AudioNodeOutput*> m_outputs;
     74 
     75     // m_renderingOutputs is a copy of m_outputs which will never be modified during the graph rendering on the audio thread.
     76     // This is the list which is used by the rendering code.
     77     // Whenever m_outputs is modified, the context is told so it can later update m_renderingOutputs from m_outputs at a safe time.
     78     // Most of the time, m_renderingOutputs is identical to m_outputs.
     79     // Oilpan: Since items are added to the vector by the audio thread (not registered to Oilpan),
     80     // we cannot use a HeapVector.
     81     GC_PLUGIN_IGNORE("http://crbug.com/404527")
     82     Vector<AudioNodeOutput*> m_renderingOutputs;
     83 
     84     // m_renderingStateNeedUpdating keeps track if m_outputs is modified.
     85     bool m_renderingStateNeedUpdating;
     86 
     87     bool m_didCallDispose;
     88 };
     89 
     90 } // namespace blink
     91 
     92 #endif // AudioSummingJunction_h
     93