OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "modules/webaudio/AudioContext.h" | 6 #include "modules/webaudio/AudioContext.h" |
7 | 7 |
8 #include "bindings/core/v8/ExceptionMessages.h" | 8 #include "bindings/core/v8/ExceptionMessages.h" |
9 #include "bindings/core/v8/ExceptionState.h" | 9 #include "bindings/core/v8/ExceptionState.h" |
10 #include "bindings/core/v8/ScriptPromiseResolver.h" | 10 #include "bindings/core/v8/ScriptPromiseResolver.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
70 fprintf(stderr, "%p: AudioContext::~AudioContext(): %u\n", this, m_contextId ); | 70 fprintf(stderr, "%p: AudioContext::~AudioContext(): %u\n", this, m_contextId ); |
71 #endif | 71 #endif |
72 } | 72 } |
73 | 73 |
74 DEFINE_TRACE(AudioContext) | 74 DEFINE_TRACE(AudioContext) |
75 { | 75 { |
76 visitor->trace(m_closeResolver); | 76 visitor->trace(m_closeResolver); |
77 AbstractAudioContext::trace(visitor); | 77 AbstractAudioContext::trace(visitor); |
78 } | 78 } |
79 | 79 |
80 ScriptPromise AudioContext::closeContext(ScriptState* scriptState) | |
81 { | |
82 if (isContextClosed()) { | |
83 // We've already closed the context previously, but it hasn't yet been r esolved, so just | |
84 // create a new promise and reject it. | |
85 return ScriptPromise::rejectWithDOMException( | |
86 scriptState, | |
87 DOMException::create(InvalidStateError, | |
88 "Cannot close a context that is being closed or has already been closed.")); | |
89 } | |
90 | |
91 m_closeResolver = ScriptPromiseResolver::create(scriptState); | |
92 ScriptPromise promise = m_closeResolver->promise(); | |
93 | |
94 // Stop the audio context. This will stop the destination node from pulling audio anymore. And | |
95 // since we have disconnected the destination from the audio graph, and thus has no references, | |
96 // the destination node can GCed if JS has no references. uninitialize() wil l also resolve the Promise | |
97 // created here. | |
98 uninitialize(); | |
99 | |
100 return promise; | |
Raymond Toy
2015/07/15 20:59:14
Is there a bug here? I don't think uninitialize()
hongchan
2015/07/15 23:24:22
I blindly merged the ToT and change the location.
| |
101 } | |
102 | |
80 ScriptPromise AudioContext::suspendContext(ScriptState* scriptState) | 103 ScriptPromise AudioContext::suspendContext(ScriptState* scriptState) |
81 { | 104 { |
82 ASSERT(isMainThread()); | 105 ASSERT(isMainThread()); |
83 AutoLocker locker(this); | 106 AutoLocker locker(this); |
84 | 107 |
85 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); | 108 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); |
86 ScriptPromise promise = resolver->promise(); | 109 ScriptPromise promise = resolver->promise(); |
87 | 110 |
88 if (contextState() == Closed) { | 111 if (contextState() == Closed) { |
89 resolver->reject( | 112 resolver->reject( |
90 DOMException::create(InvalidStateError, "Cannot suspend a context th at has been closed")); | 113 DOMException::create(InvalidStateError, "Cannot suspend a context th at has been closed")); |
91 } else { | 114 } else { |
92 // Stop rendering now. | 115 // Stop rendering now. |
93 if (destination()) | 116 if (destination()) |
94 stopRendering(); | 117 stopRendering(); |
95 | 118 |
96 // Since we don't have any way of knowing when the hardware actually sto ps, we'll just | 119 // Since we don't have any way of knowing when the hardware actually sto ps, we'll just |
97 // resolve the promise now. | 120 // resolve the promise now. |
98 resolver->resolve(); | 121 resolver->resolve(); |
99 } | 122 } |
100 | 123 |
101 return promise; | 124 return promise; |
102 } | 125 } |
103 | 126 |
127 ScriptPromise AudioContext::suspendContext(ScriptState* scriptState, double susp endTime) | |
128 { | |
129 ASSERT_NOT_REACHED(); | |
130 } | |
131 | |
104 ScriptPromise AudioContext::resumeContext(ScriptState* scriptState) | 132 ScriptPromise AudioContext::resumeContext(ScriptState* scriptState) |
105 { | 133 { |
106 ASSERT(isMainThread()); | 134 ASSERT(isMainThread()); |
107 | 135 |
108 if (isContextClosed()) { | 136 if (isContextClosed()) { |
109 return ScriptPromise::rejectWithDOMException( | 137 return ScriptPromise::rejectWithDOMException( |
110 scriptState, | 138 scriptState, |
111 DOMException::create( | 139 DOMException::create( |
112 InvalidAccessError, | 140 InvalidAccessError, |
113 "cannot resume a closed AudioContext")); | 141 "cannot resume a closed AudioContext")); |
114 } | 142 } |
115 | 143 |
116 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); | 144 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); |
117 ScriptPromise promise = resolver->promise(); | 145 ScriptPromise promise = resolver->promise(); |
118 | 146 |
119 // Restart the destination node to pull on the audio graph. | 147 // Restart the destination node to pull on the audio graph. |
120 if (destination()) | 148 if (destination()) |
121 startRendering(); | 149 startRendering(); |
122 | 150 |
123 // Save the resolver which will get resolved when the destination node start s pulling on the | 151 // Save the resolver which will get resolved when the destination node start s pulling on the |
124 // graph again. | 152 // graph again. |
125 { | 153 { |
126 AutoLocker locker(this); | 154 AutoLocker(this); |
127 m_resumeResolvers.append(resolver); | 155 m_resumeResolvers.append(resolver); |
128 } | 156 } |
129 | 157 |
130 return promise; | 158 return promise; |
131 } | 159 } |
132 | 160 |
133 ScriptPromise AudioContext::closeContext(ScriptState* scriptState) | |
134 { | |
135 if (isContextClosed()) { | |
136 // We've already closed the context previously, but it hasn't yet been r esolved, so just | |
137 // create a new promise and reject it. | |
138 return ScriptPromise::rejectWithDOMException( | |
139 scriptState, | |
140 DOMException::create(InvalidStateError, | |
141 "Cannot close a context that is being closed or has already been closed.")); | |
142 } | |
143 | |
144 m_closeResolver = ScriptPromiseResolver::create(scriptState); | |
145 ScriptPromise promise = m_closeResolver->promise(); | |
146 | |
147 // Stop the audio context. This will stop the destination node from pulling audio anymore. And | |
148 // since we have disconnected the destination from the audio graph, and thus has no references, | |
149 // the destination node can GCed if JS has no references. uninitialize() wil l also resolve the Promise | |
150 // created here. | |
151 uninitialize(); | |
152 | |
153 return promise; | |
154 } | |
155 | |
156 void AudioContext::didClose() | 161 void AudioContext::didClose() |
157 { | 162 { |
158 // This is specific to AudioContexts. OfflineAudioContexts | 163 // This is specific to AudioContexts. OfflineAudioContexts |
159 // are closed in their completion event. | 164 // are closed in their completion event. |
160 setContextState(Closed); | 165 setContextState(Closed); |
161 | 166 |
162 ASSERT(s_hardwareContextCount); | 167 ASSERT(s_hardwareContextCount); |
163 --s_hardwareContextCount; | 168 --s_hardwareContextCount; |
164 | 169 |
165 if (m_closeResolver) | 170 if (m_closeResolver) |
(...skipping 13 matching lines...) Expand all Loading... | |
179 if (contextState() == Running) { | 184 if (contextState() == Running) { |
180 destination()->audioDestinationHandler().stopRendering(); | 185 destination()->audioDestinationHandler().stopRendering(); |
181 setContextState(Suspended); | 186 setContextState(Suspended); |
182 deferredTaskHandler().clearHandlersToBeDeleted(); | 187 deferredTaskHandler().clearHandlersToBeDeleted(); |
183 } | 188 } |
184 } | 189 } |
185 | 190 |
186 } // namespace blink | 191 } // namespace blink |
187 | 192 |
188 #endif // ENABLE(WEB_AUDIO) | 193 #endif // ENABLE(WEB_AUDIO) |
OLD | NEW |