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

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

Issue 802593004: WebAudio: Fix AudioNode leak in a case that AudioNode is not disconnected from the graph explicitly. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: New marking mode, simpify WebAudio code Created 5 years, 10 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 | Annotate | Revision Log
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
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 class PannerNode; 70 class PannerNode;
71 class PeriodicWave; 71 class PeriodicWave;
72 class ScriptProcessorNode; 72 class ScriptProcessorNode;
73 class SecurityOrigin; 73 class SecurityOrigin;
74 class StereoPannerNode; 74 class StereoPannerNode;
75 class WaveShaperNode; 75 class WaveShaperNode;
76 76
77 // AudioContext is the cornerstone of the web audio API and all AudioNodes are c reated from it. 77 // AudioContext is the cornerstone of the web audio API and all AudioNodes are c reated from it.
78 // For thread safety between the audio thread and the main thread, it has a rend ering graph locking mechanism. 78 // For thread safety between the audio thread and the main thread, it has a rend ering graph locking mechanism.
79 79
80 class AudioContext : public RefCountedGarbageCollectedEventTargetWithInlineData< AudioContext>, public ActiveDOMObject { 80 class AudioContext
81 : public RefCountedGarbageCollectedEventTargetWithInlineData<AudioContext>
82 , public ActiveDOMObject
83 , private ThreadState::MarkingTask {
81 DEFINE_EVENT_TARGET_REFCOUNTING_WILL_BE_REMOVED(RefCountedGarbageCollected<A udioContext>); 84 DEFINE_EVENT_TARGET_REFCOUNTING_WILL_BE_REMOVED(RefCountedGarbageCollected<A udioContext>);
82 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(AudioContext); 85 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(AudioContext);
83 DEFINE_WRAPPERTYPEINFO(); 86 DEFINE_WRAPPERTYPEINFO();
84 public: 87 public:
85 // The state of an audio context. On creation, the state is Suspended. The state is Running if 88 // The state of an audio context. On creation, the state is Suspended. The state is Running if
86 // audio is being processed (audio graph is being pulled for data). The stat e is Closed if the 89 // audio is being processed (audio graph is being pulled for data). The stat e is Closed if the
87 // audio context has been closed. The valid transitions are from Suspended to either Running or 90 // audio context has been closed. The valid transitions are from Suspended to either Running or
88 // Closed; Running to Suspended or Closed. Once Closed, there are no valid t ransitions. 91 // Closed; Running to Suspended or Closed. Once Closed, there are no valid t ransitions.
89 enum AudioContextState { 92 enum AudioContextState {
90 Suspended, 93 Suspended,
91 Running, 94 Running,
92 Closed 95 Closed
93 }; 96 };
94 97
95 // Create an AudioContext for rendering to the audio hardware. 98 // Create an AudioContext for rendering to the audio hardware.
96 static AudioContext* create(Document&, ExceptionState&); 99 static AudioContext* create(Document&, ExceptionState&);
97 100
98 virtual ~AudioContext(); 101 virtual ~AudioContext();
99 102
100 virtual void trace(Visitor*) override; 103 virtual void trace(Visitor*) override;
101 104
102 bool isInitialized() const { return m_isInitialized; } 105 bool isInitialized() const { return m_isInitialized; }
103 bool isOfflineContext() { return m_isOfflineContext; } 106 bool isOfflineContext() { return m_isOfflineContext; }
107 AudioContextState contextState() const { return m_contextState; }
108 void setLastZombie(void*);
104 109
105 // Document notification 110 // Document notification
106 virtual void stop() override final; 111 virtual void stop() override final;
107 virtual bool hasPendingActivity() const override; 112 virtual bool hasPendingActivity() const override;
108 113
109 AudioDestinationNode* destination() { return m_destinationNode.get(); } 114 AudioDestinationNode* destination() { return m_destinationNode.get(); }
110 // currentSampleFrame() returns the current sample frame. It should only be called from the 115 // currentSampleFrame() returns the current sample frame. It should only be called from the
111 // audio thread. 116 // audio thread.
112 size_t currentSampleFrame() const { return m_destinationNode->currentSampleF rame(); } 117 size_t currentSampleFrame() const { return m_destinationNode->currentSampleF rame(); }
113 // cachedSampleFrame() is like currentSampleFrame() but must be called from the main thread to 118 // cachedSampleFrame() is like currentSampleFrame() but must be called from the main thread to
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 278
274 protected: 279 protected:
275 explicit AudioContext(Document*); 280 explicit AudioContext(Document*);
276 AudioContext(Document*, unsigned numberOfChannels, size_t numberOfFrames, fl oat sampleRate); 281 AudioContext(Document*, unsigned numberOfChannels, size_t numberOfFrames, fl oat sampleRate);
277 282
278 RefPtrWillBeMember<ScriptPromiseResolver> m_offlineResolver; 283 RefPtrWillBeMember<ScriptPromiseResolver> m_offlineResolver;
279 private: 284 private:
280 void initialize(); 285 void initialize();
281 void uninitialize(); 286 void uninitialize();
282 287
288 // ThreadState::MarkingTask functions.
289 void willStartMarking(ThreadState&) override;
290 void didFinishMarking(ThreadState&) override;
291
283 // ExecutionContext calls stop twice. 292 // ExecutionContext calls stop twice.
284 // We'd like to schedule only one stop action for them. 293 // We'd like to schedule only one stop action for them.
285 bool m_isStopScheduled; 294 bool m_isStopScheduled;
286 bool m_isCleared; 295 bool m_isCleared;
287 void clear(); 296 void clear();
288 297
289 // Set to true when the destination node has been initialized and is ready t o process data. 298 // Set to true when the destination node has been initialized and is ready t o process data.
290 bool m_isInitialized; 299 bool m_isInitialized;
291 300
292 void derefNode(AudioNode*); 301 void derefNode(AudioNode*);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 // m_automaticPullNodesNeedUpdating keeps track if m_automaticPullNodes is m odified. 389 // m_automaticPullNodesNeedUpdating keeps track if m_automaticPullNodes is m odified.
381 bool m_automaticPullNodesNeedUpdating; 390 bool m_automaticPullNodesNeedUpdating;
382 void updateAutomaticPullNodes(); 391 void updateAutomaticPullNodes();
383 392
384 unsigned m_connectionCount; 393 unsigned m_connectionCount;
385 394
386 // Graph locking. 395 // Graph locking.
387 bool m_didInitializeContextGraphMutex; 396 bool m_didInitializeContextGraphMutex;
388 RecursiveMutex m_contextGraphMutex; 397 RecursiveMutex m_contextGraphMutex;
389 volatile ThreadIdentifier m_audioThread; 398 volatile ThreadIdentifier m_audioThread;
399 // Accessing m_last*Zombie should be protected by
400 // m_didInitializeContextGraphMutex.
401 void* m_lastZombie;
402 void* m_lastRemovableZombie;
390 403
391 // Only accessed in the audio thread. 404 // Only accessed in the audio thread.
392 // Oilpan: Since items are added to these vectors by the audio thread (not r egistered to Oilpan), 405 // Oilpan: Since items are added to these vectors by the audio thread (not r egistered to Oilpan),
393 // we cannot use HeapVectors. 406 // we cannot use HeapVectors.
394 GC_PLUGIN_IGNORE("http://crbug.com/404527") 407 GC_PLUGIN_IGNORE("http://crbug.com/404527")
395 Vector<AudioNode*> m_deferredBreakConnectionList; 408 Vector<AudioNode*> m_deferredBreakConnectionList;
396 409
397 Member<AudioBuffer> m_renderTarget; 410 Member<AudioBuffer> m_renderTarget;
398 411
399 bool m_isOfflineContext; 412 bool m_isOfflineContext;
(...skipping 17 matching lines...) Expand all
417 void handleStoppableSourceNodes(); 430 void handleStoppableSourceNodes();
418 431
419 // This is considering 32 is large enough for multiple channels audio. 432 // This is considering 32 is large enough for multiple channels audio.
420 // It is somewhat arbitrary and could be increased if necessary. 433 // It is somewhat arbitrary and could be increased if necessary.
421 enum { MaxNumberOfChannels = 32 }; 434 enum { MaxNumberOfChannels = 32 };
422 }; 435 };
423 436
424 } // namespace blink 437 } // namespace blink
425 438
426 #endif // AudioContext_h 439 #endif // AudioContext_h
OLDNEW
« no previous file with comments | « no previous file | Source/modules/webaudio/AudioContext.cpp » ('j') | Source/modules/webaudio/AudioContext.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698