| 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 18 matching lines...) Expand all Loading... |
| 29 #include "modules/webaudio/OfflineAudioContext.h" | 29 #include "modules/webaudio/OfflineAudioContext.h" |
| 30 | 30 |
| 31 #include "bindings/v8/ExceptionMessages.h" | 31 #include "bindings/v8/ExceptionMessages.h" |
| 32 #include "bindings/v8/ExceptionState.h" | 32 #include "bindings/v8/ExceptionState.h" |
| 33 #include "core/dom/Document.h" | 33 #include "core/dom/Document.h" |
| 34 #include "core/dom/ExceptionCode.h" | 34 #include "core/dom/ExceptionCode.h" |
| 35 #include "core/dom/ExecutionContext.h" | 35 #include "core/dom/ExecutionContext.h" |
| 36 | 36 |
| 37 namespace WebCore { | 37 namespace WebCore { |
| 38 | 38 |
| 39 PassRefPtr<OfflineAudioContext> OfflineAudioContext::create(ExecutionContext* co
ntext, unsigned numberOfChannels, size_t numberOfFrames, float sampleRate, Excep
tionState& exceptionState) | 39 PassRefPtrWillBeRawPtr<OfflineAudioContext> OfflineAudioContext::create(Executio
nContext* context, unsigned numberOfChannels, size_t numberOfFrames, float sampl
eRate, ExceptionState& exceptionState) |
| 40 { | 40 { |
| 41 // FIXME: add support for workers. | 41 // FIXME: add support for workers. |
| 42 if (!context || !context->isDocument()) { | 42 if (!context || !context->isDocument()) { |
| 43 exceptionState.throwDOMException( | 43 exceptionState.throwDOMException( |
| 44 NotSupportedError, | 44 NotSupportedError, |
| 45 "Workers are not supported."); | 45 "Workers are not supported."); |
| 46 return nullptr; | 46 return nullptr; |
| 47 } | 47 } |
| 48 | 48 |
| 49 Document* document = toDocument(context); | 49 Document* document = toDocument(context); |
| 50 | 50 |
| 51 if (!numberOfFrames) { | 51 if (!numberOfFrames) { |
| 52 exceptionState.throwDOMException(SyntaxError, "number of frames cannot b
e zero."); | 52 exceptionState.throwDOMException(SyntaxError, "number of frames cannot b
e zero."); |
| 53 return nullptr; | 53 return nullptr; |
| 54 } | 54 } |
| 55 | 55 |
| 56 if (numberOfChannels > 10) { | 56 if (numberOfChannels > 10) { |
| 57 exceptionState.throwDOMException(SyntaxError, "number of channels (" + S
tring::number(numberOfChannels) + ") exceeds maximum (10)."); | 57 exceptionState.throwDOMException(SyntaxError, "number of channels (" + S
tring::number(numberOfChannels) + ") exceeds maximum (10)."); |
| 58 return nullptr; | 58 return nullptr; |
| 59 } | 59 } |
| 60 | 60 |
| 61 if (!isSampleRateRangeGood(sampleRate)) { | 61 if (!isSampleRateRangeGood(sampleRate)) { |
| 62 exceptionState.throwDOMException(SyntaxError, "sample rate (" + String::
number(sampleRate) + ") must be in the range 44100-96000 Hz."); | 62 exceptionState.throwDOMException(SyntaxError, "sample rate (" + String::
number(sampleRate) + ") must be in the range 44100-96000 Hz."); |
| 63 return nullptr; | 63 return nullptr; |
| 64 } | 64 } |
| 65 | 65 |
| 66 RefPtr<OfflineAudioContext> audioContext(adoptRef(new OfflineAudioContext(do
cument, numberOfChannels, numberOfFrames, sampleRate))); | 66 RefPtrWillBeRawPtr<OfflineAudioContext> audioContext(adoptRefWillBeThreadSaf
eRefCountedGarbageCollected(new OfflineAudioContext(document, numberOfChannels,
numberOfFrames, sampleRate))); |
| 67 | 67 |
| 68 if (!audioContext->destination()) { | 68 if (!audioContext->destination()) { |
| 69 exceptionState.throwDOMException( | 69 exceptionState.throwDOMException( |
| 70 NotSupportedError, | 70 NotSupportedError, |
| 71 "OfflineAudioContext(" + String::number(numberOfChannels) | 71 "OfflineAudioContext(" + String::number(numberOfChannels) |
| 72 + ", " + String::number(numberOfFrames) | 72 + ", " + String::number(numberOfFrames) |
| 73 + ", " + String::number(sampleRate) | 73 + ", " + String::number(sampleRate) |
| 74 + ")"); | 74 + ")"); |
| 75 } | 75 } |
| 76 | 76 |
| 77 audioContext->suspendIfNeeded(); | 77 audioContext->suspendIfNeeded(); |
| 78 return audioContext.release(); | 78 return audioContext.release(); |
| 79 } | 79 } |
| 80 | 80 |
| 81 OfflineAudioContext::OfflineAudioContext(Document* document, unsigned numberOfCh
annels, size_t numberOfFrames, float sampleRate) | 81 OfflineAudioContext::OfflineAudioContext(Document* document, unsigned numberOfCh
annels, size_t numberOfFrames, float sampleRate) |
| 82 : AudioContext(document, numberOfChannels, numberOfFrames, sampleRate) | 82 : AudioContext(document, numberOfChannels, numberOfFrames, sampleRate) |
| 83 { | 83 { |
| 84 ScriptWrappable::init(this); | 84 ScriptWrappable::init(this); |
| 85 } | 85 } |
| 86 | 86 |
| 87 OfflineAudioContext::~OfflineAudioContext() | 87 OfflineAudioContext::~OfflineAudioContext() |
| 88 { | 88 { |
| 89 } | 89 } |
| 90 | 90 |
| 91 } // namespace WebCore | 91 } // namespace WebCore |
| 92 | 92 |
| 93 #endif // ENABLE(WEB_AUDIO) | 93 #endif // ENABLE(WEB_AUDIO) |
| OLD | NEW |