| 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 10 matching lines...) Expand all Loading... |
| 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 #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 "bindings/core/v8/ScriptState.h" |
| 31 #include "core/dom/Document.h" | 32 #include "core/dom/Document.h" |
| 32 #include "core/dom/ExceptionCode.h" | 33 #include "core/dom/ExceptionCode.h" |
| 33 #include "core/dom/ExecutionContext.h" | 34 #include "core/dom/ExecutionContext.h" |
| 34 #include "platform/audio/AudioUtilities.h" | 35 #include "platform/audio/AudioUtilities.h" |
| 35 | 36 |
| 36 namespace blink { | 37 namespace blink { |
| 37 | 38 |
| 38 OfflineAudioContext* OfflineAudioContext::create(ExecutionContext* context, unsi
gned numberOfChannels, size_t numberOfFrames, float sampleRate, ExceptionState&
exceptionState) | 39 OfflineAudioContext* OfflineAudioContext::create(ExecutionContext* context, unsi
gned numberOfChannels, size_t numberOfFrames, float sampleRate, ExceptionState&
exceptionState) |
| 39 { | 40 { |
| 40 // FIXME: add support for workers. | 41 // FIXME: add support for workers. |
| 41 if (!context || !context->isDocument()) { | 42 if (!context || !context->isDocument()) { |
| 42 exceptionState.throwDOMException( | 43 exceptionState.throwDOMException( |
| 43 NotSupportedError, | 44 NotSupportedError, |
| 44 "Workers are not supported."); | 45 "Workers are not supported."); |
| 45 return nullptr; | 46 return nullptr; |
| 46 } | 47 } |
| 47 | 48 |
| 48 Document* document = toDocument(context); | 49 Document* document = toDocument(context); |
| 49 | 50 |
| 50 if (!numberOfFrames) { | 51 if (!numberOfFrames) { |
| 51 exceptionState.throwDOMException(SyntaxError, "number of frames cannot b
e zero."); | 52 exceptionState.throwDOMException(SyntaxError, "number of frames cannot b
e zero."); |
| 52 return nullptr; | 53 return nullptr; |
| 53 } | 54 } |
| 54 | 55 |
| 55 if (numberOfChannels > AudioContext::maxNumberOfChannels()) { | 56 if (numberOfChannels > AbstractAudioContext::maxNumberOfChannels()) { |
| 56 exceptionState.throwDOMException( | 57 exceptionState.throwDOMException( |
| 57 IndexSizeError, | 58 IndexSizeError, |
| 58 ExceptionMessages::indexOutsideRange<unsigned>( | 59 ExceptionMessages::indexOutsideRange<unsigned>( |
| 59 "number of channels", | 60 "number of channels", |
| 60 numberOfChannels, | 61 numberOfChannels, |
| 61 0, | 62 0, |
| 62 ExceptionMessages::InclusiveBound, | 63 ExceptionMessages::InclusiveBound, |
| 63 AudioContext::maxNumberOfChannels(), | 64 AbstractAudioContext::maxNumberOfChannels(), |
| 64 ExceptionMessages::InclusiveBound)); | 65 ExceptionMessages::InclusiveBound)); |
| 65 return nullptr; | 66 return nullptr; |
| 66 } | 67 } |
| 67 | 68 |
| 68 if (!AudioUtilities::isValidAudioBufferSampleRate(sampleRate)) { | 69 if (!AudioUtilities::isValidAudioBufferSampleRate(sampleRate)) { |
| 69 exceptionState.throwDOMException( | 70 exceptionState.throwDOMException( |
| 70 IndexSizeError, | 71 IndexSizeError, |
| 71 ExceptionMessages::indexOutsideRange( | 72 ExceptionMessages::indexOutsideRange( |
| 72 "sampleRate", sampleRate, | 73 "sampleRate", sampleRate, |
| 73 AudioUtilities::minAudioBufferSampleRate(), ExceptionMessages::I
nclusiveBound, | 74 AudioUtilities::minAudioBufferSampleRate(), ExceptionMessages::I
nclusiveBound, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 84 + ", " + String::number(numberOfFrames) | 85 + ", " + String::number(numberOfFrames) |
| 85 + ", " + String::number(sampleRate) | 86 + ", " + String::number(sampleRate) |
| 86 + ")"); | 87 + ")"); |
| 87 } | 88 } |
| 88 | 89 |
| 89 audioContext->suspendIfNeeded(); | 90 audioContext->suspendIfNeeded(); |
| 90 return audioContext; | 91 return audioContext; |
| 91 } | 92 } |
| 92 | 93 |
| 93 OfflineAudioContext::OfflineAudioContext(Document* document, unsigned numberOfCh
annels, size_t numberOfFrames, float sampleRate) | 94 OfflineAudioContext::OfflineAudioContext(Document* document, unsigned numberOfCh
annels, size_t numberOfFrames, float sampleRate) |
| 94 : AudioContext(document, numberOfChannels, numberOfFrames, sampleRate) | 95 : AbstractAudioContext(document, numberOfChannels, numberOfFrames, sampleRat
e) |
| 95 { | 96 { |
| 96 } | 97 } |
| 97 | 98 |
| 98 OfflineAudioContext::~OfflineAudioContext() | 99 OfflineAudioContext::~OfflineAudioContext() |
| 99 { | 100 { |
| 100 } | 101 } |
| 101 | 102 |
| 102 ScriptPromise OfflineAudioContext::startOfflineRendering(ScriptState* scriptStat
e) | 103 ScriptPromise OfflineAudioContext::startOfflineRendering(ScriptState* scriptStat
e) |
| 103 { | 104 { |
| 104 // Calling close() on an OfflineAudioContext is not supported/allowed, | 105 // Calling close() on an OfflineAudioContext is not supported/allowed, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 118 DOMException::create( | 119 DOMException::create( |
| 119 InvalidStateError, | 120 InvalidStateError, |
| 120 "cannot call startRendering more than once")); | 121 "cannot call startRendering more than once")); |
| 121 } | 122 } |
| 122 | 123 |
| 123 m_offlineResolver = ScriptPromiseResolver::create(scriptState); | 124 m_offlineResolver = ScriptPromiseResolver::create(scriptState); |
| 124 startRendering(); | 125 startRendering(); |
| 125 return m_offlineResolver->promise(); | 126 return m_offlineResolver->promise(); |
| 126 } | 127 } |
| 127 | 128 |
| 129 ScriptPromise OfflineAudioContext::closeContext(ScriptState* scriptState) |
| 130 { |
| 131 return ScriptPromise::rejectWithDOMException( |
| 132 scriptState, |
| 133 DOMException::create(InvalidAccessError, "cannot close an OfflineAudioCo
ntext.")); |
| 134 } |
| 135 |
| 136 ScriptPromise OfflineAudioContext::suspendContext(ScriptState* scriptState) |
| 137 { |
| 138 return ScriptPromise::rejectWithDOMException( |
| 139 scriptState, |
| 140 DOMException::create( |
| 141 InvalidAccessError, |
| 142 "cannot suspend an OfflineAudioContext")); |
| 143 } |
| 144 |
| 145 ScriptPromise OfflineAudioContext::resumeContext(ScriptState* scriptState) |
| 146 { |
| 147 return ScriptPromise::rejectWithDOMException( |
| 148 scriptState, |
| 149 DOMException::create( |
| 150 InvalidAccessError, |
| 151 "cannot resume an OfflineAudioContext")); |
| 152 } |
| 153 |
| 128 } // namespace blink | 154 } // namespace blink |
| 129 | 155 |
| 130 #endif // ENABLE(WEB_AUDIO) | 156 #endif // ENABLE(WEB_AUDIO) |
| OLD | NEW |