| 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 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 using namespace std; | 37 using namespace std; |
| 38 | 38 |
| 39 namespace WebCore { | 39 namespace WebCore { |
| 40 | 40 |
| 41 const size_t renderQuantumSize = 128; | 41 const size_t renderQuantumSize = 128; |
| 42 | 42 |
| 43 OfflineAudioDestinationNode::OfflineAudioDestinationNode(AudioContext* context,
AudioBuffer* renderTarget) | 43 OfflineAudioDestinationNode::OfflineAudioDestinationNode(AudioContext* context,
AudioBuffer* renderTarget) |
| 44 : AudioDestinationNode(context, renderTarget->sampleRate()) | 44 : AudioDestinationNode(context, renderTarget->sampleRate()) |
| 45 , m_renderTarget(renderTarget) | 45 , m_renderTarget(renderTarget) |
| 46 , m_renderThread(0) |
| 46 , m_startedRendering(false) | 47 , m_startedRendering(false) |
| 47 { | 48 { |
| 48 m_renderBus = adoptPtr(new AudioBus(renderTarget->numberOfChannels(), render
QuantumSize)); | 49 m_renderBus = adoptPtr(new AudioBus(renderTarget->numberOfChannels(), render
QuantumSize)); |
| 49 | 50 |
| 50 initialize(); | 51 initialize(); |
| 51 } | 52 } |
| 52 | 53 |
| 53 OfflineAudioDestinationNode::~OfflineAudioDestinationNode() | 54 OfflineAudioDestinationNode::~OfflineAudioDestinationNode() |
| 54 { | 55 { |
| 55 if (m_renderThread) | |
| 56 waitForThreadCompletion(m_renderThread, 0); | |
| 57 | |
| 58 uninitialize(); | 56 uninitialize(); |
| 59 } | 57 } |
| 60 | 58 |
| 61 void OfflineAudioDestinationNode::initialize() | 59 void OfflineAudioDestinationNode::initialize() |
| 62 { | 60 { |
| 63 if (isInitialized()) | 61 if (isInitialized()) |
| 64 return; | 62 return; |
| 65 | 63 |
| 66 AudioNode::initialize(); | 64 AudioNode::initialize(); |
| 67 } | 65 } |
| 68 | 66 |
| 69 void OfflineAudioDestinationNode::uninitialize() | 67 void OfflineAudioDestinationNode::uninitialize() |
| 70 { | 68 { |
| 71 if (!isInitialized()) | 69 if (!isInitialized()) |
| 72 return; | 70 return; |
| 73 | 71 |
| 74 AudioNode::uninitialize(); | 72 AudioNode::uninitialize(); |
| 75 } | 73 } |
| 76 | 74 |
| 77 void OfflineAudioDestinationNode::startRendering() | 75 void OfflineAudioDestinationNode::startRendering() |
| 78 { | 76 { |
| 79 ASSERT(isMainThread()); | 77 ASSERT(isMainThread()); |
| 80 ASSERT(m_renderTarget.get()); | 78 ASSERT(m_renderTarget.get()); |
| 81 if (!m_renderTarget.get()) | 79 if (!m_renderTarget.get()) |
| 82 return; | 80 return; |
| 83 | 81 |
| 84 if (!m_startedRendering) { | 82 if (!m_startedRendering) { |
| 85 m_startedRendering = true; | 83 m_startedRendering = true; |
| 84 ref(); // See corresponding deref() call in notifyCompleteDispatch(). |
| 86 m_renderThread = createThread(OfflineAudioDestinationNode::renderEntry,
this, "offline renderer"); | 85 m_renderThread = createThread(OfflineAudioDestinationNode::renderEntry,
this, "offline renderer"); |
| 87 } | 86 } |
| 88 } | 87 } |
| 89 | 88 |
| 90 // Do offline rendering in this thread. | 89 // Do offline rendering in this thread. |
| 91 void* OfflineAudioDestinationNode::renderEntry(void* threadData) | 90 void* OfflineAudioDestinationNode::renderEntry(void* threadData) |
| 92 { | 91 { |
| 93 OfflineAudioDestinationNode* destinationNode = reinterpret_cast<OfflineAudio
DestinationNode*>(threadData); | 92 OfflineAudioDestinationNode* destinationNode = reinterpret_cast<OfflineAudio
DestinationNode*>(threadData); |
| 94 ASSERT(destinationNode); | 93 ASSERT(destinationNode); |
| 95 destinationNode->render(); | 94 destinationNode->render(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 float* source = m_renderBus->channel(channelIndex)->data(); | 138 float* source = m_renderBus->channel(channelIndex)->data(); |
| 140 float* destination = m_renderTarget->getChannelData(channelIndex)->d
ata(); | 139 float* destination = m_renderTarget->getChannelData(channelIndex)->d
ata(); |
| 141 memcpy(destination + n, source, sizeof(float) * framesAvailableToCop
y); | 140 memcpy(destination + n, source, sizeof(float) * framesAvailableToCop
y); |
| 142 } | 141 } |
| 143 | 142 |
| 144 n += framesAvailableToCopy; | 143 n += framesAvailableToCopy; |
| 145 framesToProcess -= framesAvailableToCopy; | 144 framesToProcess -= framesAvailableToCopy; |
| 146 } | 145 } |
| 147 | 146 |
| 148 // Our work is done. Let the AudioContext know. | 147 // Our work is done. Let the AudioContext know. |
| 149 // See corresponding deref() call in notifyCompleteDispatch(). | |
| 150 ref(); | |
| 151 callOnMainThread(notifyCompleteDispatch, this); | 148 callOnMainThread(notifyCompleteDispatch, this); |
| 152 } | 149 } |
| 153 | 150 |
| 154 void OfflineAudioDestinationNode::notifyCompleteDispatch(void* userData) | 151 void OfflineAudioDestinationNode::notifyCompleteDispatch(void* userData) |
| 155 { | 152 { |
| 156 OfflineAudioDestinationNode* destinationNode = static_cast<OfflineAudioDesti
nationNode*>(userData); | 153 OfflineAudioDestinationNode* destinationNode = static_cast<OfflineAudioDesti
nationNode*>(userData); |
| 157 ASSERT(destinationNode); | 154 ASSERT(destinationNode); |
| 158 if (!destinationNode) | 155 if (!destinationNode) |
| 159 return; | 156 return; |
| 160 | 157 |
| 161 destinationNode->notifyComplete(); | 158 destinationNode->notifyComplete(); |
| 162 destinationNode->deref(); | 159 destinationNode->deref(); |
| 163 } | 160 } |
| 164 | 161 |
| 165 void OfflineAudioDestinationNode::notifyComplete() | 162 void OfflineAudioDestinationNode::notifyComplete() |
| 166 { | 163 { |
| 167 context()->fireCompletionEvent(); | 164 context()->fireCompletionEvent(); |
| 168 } | 165 } |
| 169 | 166 |
| 170 } // namespace WebCore | 167 } // namespace WebCore |
| 171 | 168 |
| 172 #endif // ENABLE(WEB_AUDIO) | 169 #endif // ENABLE(WEB_AUDIO) |
| OLD | NEW |