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

Side by Side Diff: third_party/WebKit/Source/modules/webaudio/BaseAudioContext.h

Issue 2103043007: Rename AbstractAudioContext to BaseAudioContext (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use ASSERT(isGraphOwner()) instead of DCHECK Created 4 years, 5 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 AbstractAudioContext_h 25 #ifndef BaseAudioContext_h
26 #define AbstractAudioContext_h 26 #define BaseAudioContext_h
27 27
28 #include "bindings/core/v8/ActiveScriptWrappable.h" 28 #include "bindings/core/v8/ActiveScriptWrappable.h"
29 #include "bindings/core/v8/ScriptPromise.h" 29 #include "bindings/core/v8/ScriptPromise.h"
30 #include "bindings/core/v8/ScriptPromiseResolver.h" 30 #include "bindings/core/v8/ScriptPromiseResolver.h"
31 #include "core/dom/ActiveDOMObject.h" 31 #include "core/dom/ActiveDOMObject.h"
32 #include "core/dom/DOMTypedArray.h" 32 #include "core/dom/DOMTypedArray.h"
33 #include "core/events/EventListener.h" 33 #include "core/events/EventListener.h"
34 #include "modules/EventTargetModules.h" 34 #include "modules/EventTargetModules.h"
35 #include "modules/ModulesExport.h" 35 #include "modules/ModulesExport.h"
36 #include "modules/webaudio/AsyncAudioDecoder.h" 36 #include "modules/webaudio/AsyncAudioDecoder.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 class PannerNode; 72 class PannerNode;
73 class PeriodicWave; 73 class PeriodicWave;
74 class PeriodicWaveConstraints; 74 class PeriodicWaveConstraints;
75 class ScriptProcessorNode; 75 class ScriptProcessorNode;
76 class ScriptPromiseResolver; 76 class ScriptPromiseResolver;
77 class ScriptState; 77 class ScriptState;
78 class SecurityOrigin; 78 class SecurityOrigin;
79 class StereoPannerNode; 79 class StereoPannerNode;
80 class WaveShaperNode; 80 class WaveShaperNode;
81 81
82 // AbstractAudioContext is the cornerstone of the web audio API and all AudioNod es are created from it. 82 // BaseAudioContext is the cornerstone of the web audio API and all AudioNodes a re created from it.
83 // For thread safety between the audio thread and the main thread, it has a rend ering graph locking mechanism. 83 // For thread safety between the audio thread and the main thread, it has a rend ering graph locking mechanism.
84 84
85 class MODULES_EXPORT AbstractAudioContext : public EventTargetWithInlineData, pu blic ActiveScriptWrappable, public ActiveDOMObject { 85 class MODULES_EXPORT BaseAudioContext : public EventTargetWithInlineData, public ActiveScriptWrappable, public ActiveDOMObject {
86 USING_GARBAGE_COLLECTED_MIXIN(AbstractAudioContext); 86 USING_GARBAGE_COLLECTED_MIXIN(BaseAudioContext);
87 DEFINE_WRAPPERTYPEINFO(); 87 DEFINE_WRAPPERTYPEINFO();
88 public: 88 public:
89 // The state of an audio context. On creation, the state is Suspended. The state is Running if 89 // The state of an audio context. On creation, the state is Suspended. The state is Running if
90 // audio is being processed (audio graph is being pulled for data). The stat e is Closed if the 90 // audio is being processed (audio graph is being pulled for data). The stat e is Closed if the
91 // audio context has been closed. The valid transitions are from Suspended to either Running or 91 // audio context has been closed. The valid transitions are from Suspended to either Running or
92 // Closed; Running to Suspended or Closed. Once Closed, there are no valid t ransitions. 92 // Closed; Running to Suspended or Closed. Once Closed, there are no valid t ransitions.
93 enum AudioContextState { 93 enum AudioContextState {
94 Suspended, 94 Suspended,
95 Running, 95 Running,
96 Closed 96 Closed
97 }; 97 };
98 98
99 // Create an AudioContext for rendering to the audio hardware. 99 // Create an AudioContext for rendering to the audio hardware.
100 static AbstractAudioContext* create(Document&, ExceptionState&); 100 static BaseAudioContext* create(Document&, ExceptionState&);
101 101
102 ~AbstractAudioContext() override; 102 ~BaseAudioContext() override;
103 103
104 DECLARE_VIRTUAL_TRACE(); 104 DECLARE_VIRTUAL_TRACE();
105 105
106 // Is the destination node initialized and ready to handle audio? 106 // Is the destination node initialized and ready to handle audio?
107 bool isDestinationInitialized() const 107 bool isDestinationInitialized() const
108 { 108 {
109 AudioDestinationNode* dest = destination(); 109 AudioDestinationNode* dest = destination();
110 return dest ? dest->audioDestinationHandler().isInitialized() : false; 110 return dest ? dest->audioDestinationHandler().isInitialized() : false;
111 } 111 }
112 112
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 // Called at the end of each render quantum. 209 // Called at the end of each render quantum.
210 void handlePostRenderTasks(); 210 void handlePostRenderTasks();
211 211
212 // Called periodically at the end of each render quantum to release finished 212 // Called periodically at the end of each render quantum to release finished
213 // source nodes. 213 // source nodes.
214 void releaseFinishedSourceNodes(); 214 void releaseFinishedSourceNodes();
215 215
216 // Keeps track of the number of connections made. 216 // Keeps track of the number of connections made.
217 void incrementConnectionCount() 217 void incrementConnectionCount()
218 { 218 {
219 ASSERT(isMainThread()); 219 DCHECK(isMainThread());
220 m_connectionCount++; 220 m_connectionCount++;
221 } 221 }
222 222
223 unsigned connectionCount() const { return m_connectionCount; } 223 unsigned connectionCount() const { return m_connectionCount; }
224 224
225 DeferredTaskHandler& deferredTaskHandler() const { return *m_deferredTaskHan dler; } 225 DeferredTaskHandler& deferredTaskHandler() const { return *m_deferredTaskHan dler; }
226 // 226 //
227 // Thread Safety and Graph Locking: 227 // Thread Safety and Graph Locking:
228 // 228 //
229 // The following functions call corresponding functions of 229 // The following functions call corresponding functions of
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 // Get the PeriodicWave for the specified oscillator type. The table is ini tialized internally 261 // Get the PeriodicWave for the specified oscillator type. The table is ini tialized internally
262 // if necessary. 262 // if necessary.
263 PeriodicWave* periodicWave(int type); 263 PeriodicWave* periodicWave(int type);
264 264
265 // Check whether the AudioContext requires a user gesture and whether the 265 // Check whether the AudioContext requires a user gesture and whether the
266 // current stack is processing user gesture and record these information in 266 // current stack is processing user gesture and record these information in
267 // a histogram. 267 // a histogram.
268 void recordUserGestureState(); 268 void recordUserGestureState();
269 269
270 protected: 270 protected:
271 explicit AbstractAudioContext(Document*); 271 explicit BaseAudioContext(Document*);
272 AbstractAudioContext(Document*, unsigned numberOfChannels, size_t numberOfFr ames, float sampleRate); 272 BaseAudioContext(Document*, unsigned numberOfChannels, size_t numberOfFrames , float sampleRate);
273 273
274 void initialize(); 274 void initialize();
275 void uninitialize(); 275 void uninitialize();
276 276
277 void setContextState(AudioContextState); 277 void setContextState(AudioContextState);
278 278
279 virtual void didClose() {} 279 virtual void didClose() {}
280 280
281 // Tries to handle AudioBufferSourceNodes that were started but became disco nnected or was never 281 // Tries to handle AudioBufferSourceNodes that were started but became disco nnected or was never
282 // connected. Because these never get pulled anymore, they will stay around forever. So if we 282 // connected. Because these never get pulled anymore, they will stay around forever. So if we
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 bool m_isResolvingResumePromises; 343 bool m_isResolvingResumePromises;
344 344
345 // Whether a user gesture is required to start this AudioContext. 345 // Whether a user gesture is required to start this AudioContext.
346 bool m_userGestureRequired; 346 bool m_userGestureRequired;
347 347
348 unsigned m_connectionCount; 348 unsigned m_connectionCount;
349 349
350 // Graph locking. 350 // Graph locking.
351 RefPtr<DeferredTaskHandler> m_deferredTaskHandler; 351 RefPtr<DeferredTaskHandler> m_deferredTaskHandler;
352 352
353 // The state of the AbstractAudioContext. 353 // The state of the BaseAudioContext.
354 AudioContextState m_contextState; 354 AudioContextState m_contextState;
355 355
356 AsyncAudioDecoder m_audioDecoder; 356 AsyncAudioDecoder m_audioDecoder;
357 357
358 // When a context is closed, the sample rate is cleared. But decodeAudioDat a can be called 358 // When a context is closed, the sample rate is cleared. But decodeAudioDat a can be called
359 // after the context has been closed and it needs the sample rate. When the context is closed, 359 // after the context has been closed and it needs the sample rate. When the context is closed,
360 // the sample rate is saved here. 360 // the sample rate is saved here.
361 float m_closedContextSampleRate; 361 float m_closedContextSampleRate;
362 362
363 // Vector of promises created by decodeAudioData. This keeps the resolvers alive until 363 // Vector of promises created by decodeAudioData. This keeps the resolvers alive until
364 // decodeAudioData finishes decoding and can tell the main thread to resolve them. 364 // decodeAudioData finishes decoding and can tell the main thread to resolve them.
365 HeapHashSet<Member<ScriptPromiseResolver>> m_decodeAudioResolvers; 365 HeapHashSet<Member<ScriptPromiseResolver>> m_decodeAudioResolvers;
366 366
367 // PeriodicWave's for the builtin oscillator types. These only depend on th e sample rate. so 367 // PeriodicWave's for the builtin oscillator types. These only depend on th e sample rate. so
368 // they can be shared with all OscillatorNodes in the context. To conserve memory, these are 368 // they can be shared with all OscillatorNodes in the context. To conserve memory, these are
369 // lazily initiialized on first use. 369 // lazily initiialized on first use.
370 Member<PeriodicWave> m_periodicWaveSine; 370 Member<PeriodicWave> m_periodicWaveSine;
371 Member<PeriodicWave> m_periodicWaveSquare; 371 Member<PeriodicWave> m_periodicWaveSquare;
372 Member<PeriodicWave> m_periodicWaveSawtooth; 372 Member<PeriodicWave> m_periodicWaveSawtooth;
373 Member<PeriodicWave> m_periodicWaveTriangle; 373 Member<PeriodicWave> m_periodicWaveTriangle;
374 374
375 // This is considering 32 is large enough for multiple channels audio. 375 // This is considering 32 is large enough for multiple channels audio.
376 // It is somewhat arbitrary and could be increased if necessary. 376 // It is somewhat arbitrary and could be increased if necessary.
377 enum { MaxNumberOfChannels = 32 }; 377 enum { MaxNumberOfChannels = 32 };
378 }; 378 };
379 379
380 } // namespace blink 380 } // namespace blink
381 381
382 #endif // AbstractAudioContext_h 382 #endif // BaseAudioContext_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698