Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012, Google Inc. All rights reserved. | 2 * Copyright (C) 2012, 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 13 matching lines...) Expand all Loading... | |
| 24 | 24 |
| 25 #include "config.h" | 25 #include "config.h" |
| 26 #if ENABLE(WEB_AUDIO) | 26 #if ENABLE(WEB_AUDIO) |
| 27 #include "modules/webaudio/OfflineAudioContext.h" | 27 #include "modules/webaudio/OfflineAudioContext.h" |
| 28 | 28 |
| 29 #include "bindings/core/v8/ExceptionMessages.h" | 29 #include "bindings/core/v8/ExceptionMessages.h" |
| 30 #include "bindings/core/v8/ExceptionState.h" | 30 #include "bindings/core/v8/ExceptionState.h" |
| 31 #include "core/dom/Document.h" | 31 #include "core/dom/Document.h" |
| 32 #include "core/dom/ExceptionCode.h" | 32 #include "core/dom/ExceptionCode.h" |
| 33 #include "core/dom/ExecutionContext.h" | 33 #include "core/dom/ExecutionContext.h" |
| 34 #include "modules/webaudio/OfflineAudioDestinationNode.h" | |
| 35 #include "platform/ThreadSafeFunctional.h" | |
| 34 #include "platform/audio/AudioUtilities.h" | 36 #include "platform/audio/AudioUtilities.h" |
| 37 #include "public/platform/Platform.h" | |
| 35 | 38 |
| 36 namespace blink { | 39 namespace blink { |
| 37 | 40 |
| 38 OfflineAudioContext* OfflineAudioContext::create(ExecutionContext* context, unsi gned numberOfChannels, size_t numberOfFrames, float sampleRate, ExceptionState& exceptionState) | 41 OfflineAudioContext* OfflineAudioContext::create(ExecutionContext* context, unsi gned numberOfChannels, size_t numberOfFrames, float sampleRate, ExceptionState& exceptionState) |
| 39 { | 42 { |
| 40 // FIXME: add support for workers. | 43 // FIXME: add support for workers. |
| 41 if (!context || !context->isDocument()) { | 44 if (!context || !context->isDocument()) { |
| 42 exceptionState.throwDOMException( | 45 exceptionState.throwDOMException( |
| 43 NotSupportedError, | 46 NotSupportedError, |
| 44 "Workers are not supported."); | 47 "Workers are not supported."); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 + ", " + String::number(sampleRate) | 88 + ", " + String::number(sampleRate) |
| 86 + ")"); | 89 + ")"); |
| 87 } | 90 } |
| 88 | 91 |
| 89 audioContext->suspendIfNeeded(); | 92 audioContext->suspendIfNeeded(); |
| 90 return audioContext; | 93 return audioContext; |
| 91 } | 94 } |
| 92 | 95 |
| 93 OfflineAudioContext::OfflineAudioContext(Document* document, unsigned numberOfCh annels, size_t numberOfFrames, float sampleRate) | 96 OfflineAudioContext::OfflineAudioContext(Document* document, unsigned numberOfCh annels, size_t numberOfFrames, float sampleRate) |
| 94 : AudioContext(document, numberOfChannels, numberOfFrames, sampleRate) | 97 : AudioContext(document, numberOfChannels, numberOfFrames, sampleRate) |
| 98 , m_isSuspendScheduled(false) | |
| 99 , m_suspendTime(-0.0) | |
|
Raymond Toy
2015/05/13 17:16:08
Why -0.0? This probably won't do what you think i
hongchan
2015/05/13 17:30:53
What would be the proper 'null' value for this cas
| |
| 95 { | 100 { |
| 96 } | 101 } |
| 97 | 102 |
| 98 OfflineAudioContext::~OfflineAudioContext() | 103 OfflineAudioContext::~OfflineAudioContext() |
| 99 { | 104 { |
| 100 } | 105 } |
| 101 | 106 |
| 107 bool OfflineAudioContext::suspendIfNecessary() | |
| 108 { | |
| 109 ASSERT(!isMainThread()); | |
| 110 | |
| 111 if (m_isSuspendScheduled && m_suspendTime <= currentTime()) { | |
| 112 m_isSuspendScheduled = false; | |
| 113 m_suspendTime = -0.0; | |
| 114 return true; | |
| 115 } | |
| 116 | |
| 117 return false; | |
| 118 } | |
| 119 | |
| 102 ScriptPromise OfflineAudioContext::startOfflineRendering(ScriptState* scriptStat e) | 120 ScriptPromise OfflineAudioContext::startOfflineRendering(ScriptState* scriptStat e) |
| 103 { | 121 { |
| 122 ASSERT(isMainThread()); | |
| 123 AutoLocker locker(this); | |
| 124 | |
| 104 // Calling close() on an OfflineAudioContext is not supported/allowed, | 125 // Calling close() on an OfflineAudioContext is not supported/allowed, |
| 105 // but it might well have been stopped by its execution context. | 126 // but it might well have been stopped by its execution context. |
| 106 if (isContextClosed()) { | 127 if (isContextClosed()) { |
| 107 return ScriptPromise::rejectWithDOMException( | 128 return ScriptPromise::rejectWithDOMException( |
| 108 scriptState, | 129 scriptState, |
| 109 DOMException::create( | 130 DOMException::create( |
| 110 InvalidStateError, | 131 InvalidStateError, |
| 111 "cannot call startRendering on an OfflineAudioContext in a stopp ed state.")); | 132 "cannot call startRendering on an OfflineAudioContext in a stopp ed state.")); |
| 112 } | 133 } |
| 113 | 134 |
| 114 if (m_offlineResolver) { | 135 if (m_offlineResolver) { |
| 115 // Can't call startRendering more than once. Return a rejected promise now. | 136 // Can't call startRendering more than once. Return a rejected promise now. |
| 116 return ScriptPromise::rejectWithDOMException( | 137 return ScriptPromise::rejectWithDOMException( |
| 117 scriptState, | 138 scriptState, |
| 118 DOMException::create( | 139 DOMException::create( |
| 119 InvalidStateError, | 140 InvalidStateError, |
| 120 "cannot call startRendering more than once")); | 141 "cannot call startRendering more than once")); |
| 121 } | 142 } |
| 122 | 143 |
| 123 m_offlineResolver = ScriptPromiseResolver::create(scriptState); | 144 m_offlineResolver = ScriptPromiseResolver::create(scriptState); |
| 124 startRendering(); | 145 |
| 146 // This calls AudioContext.startRendering(). It seems to be odd to go up the | |
| 147 // chain and call the parent's method, but the current OAC is basically a | |
| 148 // thin wrapper on AudioContext. (a container-like object.) | |
| 149 // | |
| 150 // If we decide to fix this structural issue completely, we have to touch | |
| 151 // AudioContext and AudioNode. | |
| 152 // startRendering(); | |
| 153 | |
| 154 destination()->audioDestinationHandler().startRendering(); | |
| 155 setContextState(Running); | |
| 156 | |
| 125 return m_offlineResolver->promise(); | 157 return m_offlineResolver->promise(); |
| 126 } | 158 } |
| 127 | 159 |
| 160 ScriptPromise OfflineAudioContext::suspendOfflineRendering(ScriptState* scriptSt ate, double suspendTime) | |
| 161 { | |
| 162 ASSERT(isMainThread()); | |
| 163 AutoLocker locker(this); | |
| 164 | |
| 165 // suspendTime should be greater than currentTime. Otherwise stop the | |
| 166 // rendering as soon as possible. | |
| 167 // | |
| 168 // TODO: add extra time when suspendTime is earlier than currentTime | |
| 169 if (currentTime() < suspendTime) { | |
| 170 m_isSuspendScheduled = true; | |
| 171 m_suspendTime = suspendTime; | |
| 172 } | |
| 173 | |
| 174 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); | |
| 175 ScriptPromise promise = resolver->promise(); | |
| 176 m_offlineSuspendResolvers.append(resolver); | |
| 177 | |
| 178 // fprintf(stderr, "suspend scheduled = %f\n", m_suspendTime); | |
| 179 | |
| 180 return promise; | |
| 181 } | |
| 182 | |
| 183 ScriptPromise OfflineAudioContext::resumeOfflineRendering(ScriptState* scriptSta te) | |
| 184 { | |
| 185 ASSERT(isMainThread()); | |
| 186 AutoLocker locker(this); | |
| 187 | |
| 188 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); | |
| 189 ScriptPromise promise = resolver->promise(); | |
| 190 m_offlineResumeResolvers.append(resolver); | |
| 191 | |
| 192 // Calling startRendering() in OfflineAudioDestinationHandler. | |
| 193 destination()->audioDestinationHandler().startRendering(); | |
| 194 setContextState(Running); | |
| 195 | |
| 196 return promise; | |
| 197 } | |
| 198 | |
| 128 } // namespace blink | 199 } // namespace blink |
| 129 | 200 |
| 130 #endif // ENABLE(WEB_AUDIO) | 201 #endif // ENABLE(WEB_AUDIO) |
| OLD | NEW |