Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(310)

Side by Side Diff: Source/modules/webaudio/ScriptProcessorNode.h

Issue 14028011: Made AudioNode an EventTarget (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Made AudioNode an EventTarget Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010, Google Inc. All rights reserved. 2 * Copyright (C) 2010, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN Y 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN Y
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 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 AN Y 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN Y
17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 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 O N 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O N
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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 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. 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */ 23 */
24 24
25 #ifndef ScriptProcessorNode_h 25 #ifndef ScriptProcessorNode_h
26 #define ScriptProcessorNode_h 26 #define ScriptProcessorNode_h
27 27
28 #include "ActiveDOMObject.h"
29 #include "AudioBus.h" 28 #include "AudioBus.h"
30 #include "AudioNode.h" 29 #include "AudioNode.h"
31 #include "EventListener.h"
32 #include "EventTarget.h"
33 #include <wtf/Forward.h> 30 #include <wtf/Forward.h>
34 #include <wtf/PassRefPtr.h> 31 #include <wtf/PassRefPtr.h>
35 #include <wtf/RefPtr.h> 32 #include <wtf/RefPtr.h>
36 #include <wtf/Vector.h> 33 #include <wtf/Vector.h>
37 34
38 namespace WebCore { 35 namespace WebCore {
39 36
40 class AudioBuffer; 37 class AudioBuffer;
41 class AudioContext; 38 class AudioContext;
42 class AudioProcessingEvent; 39 class AudioProcessingEvent;
43 40
44 // ScriptProcessorNode is an AudioNode which allows for arbitrary synthesis or p rocessing directly using JavaScript. 41 // ScriptProcessorNode is an AudioNode which allows for arbitrary synthesis or p rocessing directly using JavaScript.
45 // The API allows for a variable number of inputs and outputs, although it must have at least one input or output. 42 // The API allows for a variable number of inputs and outputs, although it must have at least one input or output.
46 // This basic implementation supports no more than one input and output. 43 // This basic implementation supports no more than one input and output.
47 // The "onaudioprocess" attribute is an event listener which will get called per iodically with an AudioProcessingEvent which has 44 // The "onaudioprocess" attribute is an event listener which will get called per iodically with an AudioProcessingEvent which has
48 // AudioBuffers for each input and output. 45 // AudioBuffers for each input and output.
49 46
50 // FIXME: EventTarget should be introduced at the base of the inheritance hierar chy (i.e., as a base class for AudioNode). 47 class ScriptProcessorNode : public AudioNode {
51 class ScriptProcessorNode : public AudioNode, public EventTarget {
52 public: 48 public:
53 // bufferSize must be one of the following values: 256, 512, 1024, 2048, 409 6, 8192, 16384. 49 // bufferSize must be one of the following values: 256, 512, 1024, 2048, 409 6, 8192, 16384.
54 // This value controls how frequently the onaudioprocess event handler is ca lled and how many sample-frames need to be processed each call. 50 // This value controls how frequently the onaudioprocess event handler is ca lled and how many sample-frames need to be processed each call.
55 // Lower numbers for bufferSize will result in a lower (better) latency. Hig her numbers will be necessary to avoid audio breakup and glitches. 51 // Lower numbers for bufferSize will result in a lower (better) latency. Hig her numbers will be necessary to avoid audio breakup and glitches.
56 // The value chosen must carefully balance between latency and audio quality . 52 // The value chosen must carefully balance between latency and audio quality .
57 static PassRefPtr<ScriptProcessorNode> create(AudioContext*, float sampleRat e, size_t bufferSize, unsigned numberOfInputChannels, unsigned numberOfOutputCha nnels); 53 static PassRefPtr<ScriptProcessorNode> create(AudioContext*, float sampleRat e, size_t bufferSize, unsigned numberOfInputChannels, unsigned numberOfOutputCha nnels);
58 54
59 virtual ~ScriptProcessorNode(); 55 virtual ~ScriptProcessorNode();
60 56
61 // AudioNode 57 // AudioNode
62 virtual void process(size_t framesToProcess); 58 virtual void process(size_t framesToProcess);
63 virtual void reset(); 59 virtual void reset();
64 virtual void initialize(); 60 virtual void initialize();
65 virtual void uninitialize(); 61 virtual void uninitialize();
66 62
67 // EventTarget
68 virtual const AtomicString& interfaceName() const;
69 virtual ScriptExecutionContext* scriptExecutionContext() const;
70 virtual EventTargetData* eventTargetData() { return &m_eventTargetData; }
71 virtual EventTargetData* ensureEventTargetData() { return &m_eventTargetDat a; }
72
73 size_t bufferSize() const { return m_bufferSize; } 63 size_t bufferSize() const { return m_bufferSize; }
74 64
75 DEFINE_ATTRIBUTE_EVENT_LISTENER(audioprocess); 65 DEFINE_ATTRIBUTE_EVENT_LISTENER(audioprocess);
76 66
77 // Reconcile ref/deref which are defined both in AudioNode and EventTarget.
78 using AudioNode::ref;
79 using AudioNode::deref;
Chris Rogers 2013/04/16 21:03:03 Don't we need these in AudioNode.h now?
russell.mcclellan 2013/04/17 01:59:45 No, we don't need these because they are defined i
80 67
81 private: 68 private:
82 virtual double tailTime() const OVERRIDE; 69 virtual double tailTime() const OVERRIDE;
83 virtual double latencyTime() const OVERRIDE; 70 virtual double latencyTime() const OVERRIDE;
84 71
85 ScriptProcessorNode(AudioContext*, float sampleRate, size_t bufferSize, unsi gned numberOfInputChannels, unsigned numberOfOutputChannels); 72 ScriptProcessorNode(AudioContext*, float sampleRate, size_t bufferSize, unsi gned numberOfInputChannels, unsigned numberOfOutputChannels);
86 73
87 static void fireProcessEventDispatch(void* userData); 74 static void fireProcessEventDispatch(void* userData);
88 void fireProcessEvent(); 75 void fireProcessEvent();
89 76
90 // Double buffering 77 // Double buffering
91 unsigned doubleBufferIndex() const { return m_doubleBufferIndex; } 78 unsigned doubleBufferIndex() const { return m_doubleBufferIndex; }
92 void swapBuffers() { m_doubleBufferIndex = 1 - m_doubleBufferIndex; } 79 void swapBuffers() { m_doubleBufferIndex = 1 - m_doubleBufferIndex; }
93 unsigned m_doubleBufferIndex; 80 unsigned m_doubleBufferIndex;
94 unsigned m_doubleBufferIndexForEvent; 81 unsigned m_doubleBufferIndexForEvent;
95 Vector<RefPtr<AudioBuffer> > m_inputBuffers; 82 Vector<RefPtr<AudioBuffer> > m_inputBuffers;
96 Vector<RefPtr<AudioBuffer> > m_outputBuffers; 83 Vector<RefPtr<AudioBuffer> > m_outputBuffers;
97 84
98 virtual void refEventTarget() { ref(); }
99 virtual void derefEventTarget() { deref(); }
100 EventTargetData m_eventTargetData;
101
102 size_t m_bufferSize; 85 size_t m_bufferSize;
103 unsigned m_bufferReadWriteIndex; 86 unsigned m_bufferReadWriteIndex;
104 volatile bool m_isRequestOutstanding; 87 volatile bool m_isRequestOutstanding;
105 88
106 unsigned m_numberOfInputChannels; 89 unsigned m_numberOfInputChannels;
107 unsigned m_numberOfOutputChannels; 90 unsigned m_numberOfOutputChannels;
108 91
109 AudioBus m_internalInputBus; 92 AudioBus m_internalInputBus;
110 }; 93 };
111 94
112 } // namespace WebCore 95 } // namespace WebCore
113 96
114 #endif // ScriptProcessorNode_h 97 #endif // ScriptProcessorNode_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698