| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011, Google Inc. All rights reserved. | 2 * Copyright (C) 2011, 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 | 26 |
| 27 #if ENABLE(WEB_AUDIO) | 27 #if ENABLE(WEB_AUDIO) |
| 28 | 28 |
| 29 #include "modules/webaudio/OfflineAudioDestinationNode.h" | 29 #include "modules/webaudio/OfflineAudioDestinationNode.h" |
| 30 | 30 |
| 31 #include <algorithm> | 31 #include "core/dom/CrossThreadTask.h" |
| 32 #include "modules/webaudio/AudioContext.h" |
| 33 #include "platform/Task.h" |
| 32 #include "platform/audio/AudioBus.h" | 34 #include "platform/audio/AudioBus.h" |
| 33 #include "platform/audio/HRTFDatabaseLoader.h" | 35 #include "platform/audio/HRTFDatabaseLoader.h" |
| 34 #include "modules/webaudio/AudioContext.h" | |
| 35 #include "platform/Task.h" | |
| 36 #include "public/platform/Platform.h" | 36 #include "public/platform/Platform.h" |
| 37 #include "wtf/MainThread.h" | 37 #include <algorithm> |
| 38 | 38 |
| 39 namespace blink { | 39 namespace blink { |
| 40 | 40 |
| 41 #if !ENABLE(OILPAN) |
| 42 // We need a dedicated specialization for OfflineAudioDestinationNode because it |
| 43 // doesn't inherit from RefCounted. |
| 44 template<> struct CrossThreadCopierBase<false, false, false, PassRefPtr<OfflineA
udioDestinationNode> > : public CrossThreadCopierPassThrough<PassRefPtr<OfflineA
udioDestinationNode> > { |
| 45 }; |
| 46 #endif |
| 47 |
| 41 const size_t renderQuantumSize = 128; | 48 const size_t renderQuantumSize = 128; |
| 42 | 49 |
| 43 OfflineAudioDestinationNode::OfflineAudioDestinationNode(AudioContext* context,
AudioBuffer* renderTarget) | 50 OfflineAudioDestinationNode::OfflineAudioDestinationNode(AudioContext* context,
AudioBuffer* renderTarget) |
| 44 : AudioDestinationNode(context, renderTarget->sampleRate()) | 51 : AudioDestinationNode(context, renderTarget->sampleRate()) |
| 45 , m_renderTarget(renderTarget) | 52 , m_renderTarget(renderTarget) |
| 46 , m_startedRendering(false) | 53 , m_startedRendering(false) |
| 47 { | 54 { |
| 48 m_renderBus = AudioBus::create(renderTarget->numberOfChannels(), renderQuant
umSize); | 55 m_renderBus = AudioBus::create(renderTarget->numberOfChannels(), renderQuant
umSize); |
| 49 } | 56 } |
| 50 | 57 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 80 | 87 |
| 81 void OfflineAudioDestinationNode::startRendering() | 88 void OfflineAudioDestinationNode::startRendering() |
| 82 { | 89 { |
| 83 ASSERT(isMainThread()); | 90 ASSERT(isMainThread()); |
| 84 ASSERT(m_renderTarget.get()); | 91 ASSERT(m_renderTarget.get()); |
| 85 if (!m_renderTarget.get()) | 92 if (!m_renderTarget.get()) |
| 86 return; | 93 return; |
| 87 | 94 |
| 88 if (!m_startedRendering) { | 95 if (!m_startedRendering) { |
| 89 m_startedRendering = true; | 96 m_startedRendering = true; |
| 90 m_keepAliveWhileRendering = this; | |
| 91 m_renderThread = adoptPtr(blink::Platform::current()->createThread("Offl
ine Audio Renderer")); | 97 m_renderThread = adoptPtr(blink::Platform::current()->createThread("Offl
ine Audio Renderer")); |
| 92 m_renderThread->postTask(new Task(WTF::bind(&OfflineAudioDestinationNode
::offlineRender, this))); | 98 m_renderThread->postTask(new Task(bind(&OfflineAudioDestinationNode::off
lineRender, PassRefPtrWillBeRawPtr<OfflineAudioDestinationNode>(this)))); |
| 93 } | 99 } |
| 94 } | 100 } |
| 95 | 101 |
| 96 void OfflineAudioDestinationNode::offlineRender() | 102 void OfflineAudioDestinationNode::offlineRender() |
| 97 { | 103 { |
| 98 ASSERT(!isMainThread()); | 104 ASSERT(!isMainThread()); |
| 99 ASSERT(m_renderBus.get()); | 105 ASSERT(m_renderBus.get()); |
| 100 if (!m_renderBus.get()) | 106 if (!m_renderBus.get()) |
| 101 return; | 107 return; |
| 102 | 108 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 131 const float* source = m_renderBus->channel(channelIndex)->data(); | 137 const float* source = m_renderBus->channel(channelIndex)->data(); |
| 132 float* destination = m_renderTarget->getChannelData(channelIndex)->d
ata(); | 138 float* destination = m_renderTarget->getChannelData(channelIndex)->d
ata(); |
| 133 memcpy(destination + n, source, sizeof(float) * framesAvailableToCop
y); | 139 memcpy(destination + n, source, sizeof(float) * framesAvailableToCop
y); |
| 134 } | 140 } |
| 135 | 141 |
| 136 n += framesAvailableToCopy; | 142 n += framesAvailableToCopy; |
| 137 framesToProcess -= framesAvailableToCopy; | 143 framesToProcess -= framesAvailableToCopy; |
| 138 } | 144 } |
| 139 | 145 |
| 140 // Our work is done. Let the AudioContext know. | 146 // Our work is done. Let the AudioContext know. |
| 141 callOnMainThread(notifyCompleteDispatch, this); | 147 if (context()->executionContext()) |
| 142 } | 148 context()->executionContext()->postTask(createCrossThreadTask(&OfflineAu
dioDestinationNode::notifyComplete, PassRefPtrWillBeRawPtr<OfflineAudioDestinati
onNode>(this))); |
| 143 | |
| 144 void OfflineAudioDestinationNode::notifyCompleteDispatch(void* userData) | |
| 145 { | |
| 146 OfflineAudioDestinationNode* destinationNode = static_cast<OfflineAudioDesti
nationNode*>(userData); | |
| 147 ASSERT(destinationNode); | |
| 148 if (!destinationNode) | |
| 149 return; | |
| 150 | |
| 151 destinationNode->notifyComplete(); | |
| 152 destinationNode->m_keepAliveWhileRendering.clear(); | |
| 153 } | 149 } |
| 154 | 150 |
| 155 void OfflineAudioDestinationNode::notifyComplete() | 151 void OfflineAudioDestinationNode::notifyComplete() |
| 156 { | 152 { |
| 157 context()->fireCompletionEvent(); | 153 context()->fireCompletionEvent(); |
| 158 } | 154 } |
| 159 | 155 |
| 160 void OfflineAudioDestinationNode::trace(Visitor* visitor) | 156 void OfflineAudioDestinationNode::trace(Visitor* visitor) |
| 161 { | 157 { |
| 162 visitor->trace(m_renderTarget); | 158 visitor->trace(m_renderTarget); |
| 163 AudioDestinationNode::trace(visitor); | 159 AudioDestinationNode::trace(visitor); |
| 164 } | 160 } |
| 165 | 161 |
| 166 } // namespace blink | 162 } // namespace blink |
| 167 | 163 |
| 168 #endif // ENABLE(WEB_AUDIO) | 164 #endif // ENABLE(WEB_AUDIO) |
| OLD | NEW |