OLD | NEW |
---|---|
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 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 // This basic implementation supports no more than one input and output. | 43 // This basic implementation supports no more than one input and output. |
44 // 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 |
45 // AudioBuffers for each input and output. | 45 // AudioBuffers for each input and output. |
46 | 46 |
47 class ScriptProcessorNode FINAL : public AudioNode { | 47 class ScriptProcessorNode FINAL : public AudioNode { |
48 public: | 48 public: |
49 // 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. |
50 // 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. |
51 // 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. |
52 // The value chosen must carefully balance between latency and audio quality . | 52 // The value chosen must carefully balance between latency and audio quality . |
53 static PassRefPtr<ScriptProcessorNode> create(AudioContext*, float sampleRat e, size_t bufferSize, unsigned numberOfInputChannels, unsigned numberOfOutputCha nnels); | 53 static PassRefPtrWillBeRawPtr<ScriptProcessorNode> create(AudioContext*, flo at sampleRate, size_t bufferSize, unsigned numberOfInputChannels, unsigned numbe rOfOutputChannels); |
54 | 54 |
55 virtual ~ScriptProcessorNode(); | 55 virtual ~ScriptProcessorNode(); |
56 | 56 |
57 // AudioNode | 57 // AudioNode |
58 virtual void process(size_t framesToProcess) OVERRIDE; | 58 virtual void process(size_t framesToProcess) OVERRIDE; |
59 virtual void initialize() OVERRIDE; | 59 virtual void initialize() OVERRIDE; |
60 virtual void uninitialize() OVERRIDE; | 60 virtual void uninitialize() OVERRIDE; |
61 | 61 |
62 size_t bufferSize() const { return m_bufferSize; } | 62 size_t bufferSize() const { return m_bufferSize; } |
63 | 63 |
64 DEFINE_ATTRIBUTE_EVENT_LISTENER(audioprocess); | 64 DEFINE_ATTRIBUTE_EVENT_LISTENER(audioprocess); |
65 | 65 |
66 #if ENABLE(OILPAN) | |
67 virtual void clearKeepAlive() OVERRIDE; | |
68 #endif | |
69 | |
70 void trace(Visitor*); | |
66 | 71 |
67 private: | 72 private: |
68 virtual double tailTime() const OVERRIDE; | 73 virtual double tailTime() const OVERRIDE; |
69 virtual double latencyTime() const OVERRIDE; | 74 virtual double latencyTime() const OVERRIDE; |
70 | 75 |
71 ScriptProcessorNode(AudioContext*, float sampleRate, size_t bufferSize, unsi gned numberOfInputChannels, unsigned numberOfOutputChannels); | 76 ScriptProcessorNode(AudioContext*, float sampleRate, size_t bufferSize, unsi gned numberOfInputChannels, unsigned numberOfOutputChannels); |
72 | 77 |
73 static void fireProcessEventDispatch(void* userData); | 78 static void fireProcessEventDispatch(void* userData); |
74 void fireProcessEvent(); | 79 void fireProcessEvent(); |
75 | 80 |
76 // Double buffering | 81 // Double buffering |
77 unsigned doubleBufferIndex() const { return m_doubleBufferIndex; } | 82 unsigned doubleBufferIndex() const { return m_doubleBufferIndex; } |
78 void swapBuffers() { m_doubleBufferIndex = 1 - m_doubleBufferIndex; } | 83 void swapBuffers() { m_doubleBufferIndex = 1 - m_doubleBufferIndex; } |
79 unsigned m_doubleBufferIndex; | 84 unsigned m_doubleBufferIndex; |
80 unsigned m_doubleBufferIndexForEvent; | 85 unsigned m_doubleBufferIndexForEvent; |
81 Vector<RefPtr<AudioBuffer> > m_inputBuffers; | 86 WillBeHeapVector<RefPtrWillBeMember<AudioBuffer> > m_inputBuffers; |
82 Vector<RefPtr<AudioBuffer> > m_outputBuffers; | 87 WillBeHeapVector<RefPtrWillBeMember<AudioBuffer> > m_outputBuffers; |
83 | 88 |
84 size_t m_bufferSize; | 89 size_t m_bufferSize; |
85 unsigned m_bufferReadWriteIndex; | 90 unsigned m_bufferReadWriteIndex; |
86 | 91 |
87 unsigned m_numberOfInputChannels; | 92 unsigned m_numberOfInputChannels; |
88 unsigned m_numberOfOutputChannels; | 93 unsigned m_numberOfOutputChannels; |
89 | 94 |
90 RefPtr<AudioBus> m_internalInputBus; | 95 RefPtr<AudioBus> m_internalInputBus; |
91 | 96 |
92 // Synchronize process() with fireProcessEvent(). | 97 // Synchronize process() with fireProcessEvent(). |
93 mutable Mutex m_processEventLock; | 98 mutable Mutex m_processEventLock; |
99 | |
100 #if ENABLE(OILPAN) | |
101 // AudioNodes are still reference counted but they are in the | |
102 // oilpan heap because the ScriptProcessorNode is an EventTarget. | |
103 // This self-persistent keeps the object from being deleted | |
104 // until the reference count reaches zero. | |
105 // | |
106 // It is safe to drop the self-persistent when the ref count | |
107 // of a ScriptProcessorNode reaches zero. At that point, the | |
108 // ScriptProcessor node is removed from the AudioContext and | |
109 // it cannot be reattached. Therefore, the reference count | |
110 // will not go above zero again. | |
111 OwnPtr<Persistent<AudioNode> > m_keepAlive; | |
Mads Ager (chromium)
2014/04/03 08:39:33
This has to be in AudioNode. When the ref count in
keishi
2014/04/08 02:33:40
Done.
| |
112 #endif | |
94 }; | 113 }; |
95 | 114 |
96 } // namespace WebCore | 115 } // namespace WebCore |
97 | 116 |
98 #endif // ScriptProcessorNode_h | 117 #endif // ScriptProcessorNode_h |
OLD | NEW |