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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 | 168 |
169 void OfflineAudioDestinationHandler::doOfflineRendering() { | 169 void OfflineAudioDestinationHandler::doOfflineRendering() { |
170 DCHECK(!isMainThread()); | 170 DCHECK(!isMainThread()); |
171 | 171 |
172 unsigned numberOfChannels = m_renderTarget->numberOfChannels(); | 172 unsigned numberOfChannels = m_renderTarget->numberOfChannels(); |
173 | 173 |
174 // Reset the suspend flag. | 174 // Reset the suspend flag. |
175 m_shouldSuspend = false; | 175 m_shouldSuspend = false; |
176 | 176 |
177 // If there is more to process and there is no suspension at the moment, | 177 // If there is more to process and there is no suspension at the moment, |
178 // do continue to render quanta. Then calling OfflineAudioContext.resume() wil
l pick up | 178 // do continue to render quanta. Then calling OfflineAudioContext.resume() |
179 // the render loop again from where it was suspended. | 179 // will pick up the render loop again from where it was suspended. |
180 while (m_framesToProcess > 0 && !m_shouldSuspend) { | 180 while (m_framesToProcess > 0 && !m_shouldSuspend) { |
181 // Suspend the rendering and update m_shouldSuspend if a scheduled | 181 // Suspend the rendering and update m_shouldSuspend if a scheduled |
182 // suspend found at the current sample frame. Otherwise render one | 182 // suspend found at the current sample frame. Otherwise render one |
183 // quantum and return false. | 183 // quantum and return false. |
184 m_shouldSuspend = | 184 m_shouldSuspend = |
185 renderIfNotSuspended(0, m_renderBus.get(), renderQuantumSize); | 185 renderIfNotSuspended(0, m_renderBus.get(), renderQuantumSize); |
186 | 186 |
187 if (m_shouldSuspend) | 187 if (m_shouldSuspend) |
188 return; | 188 return; |
189 | 189 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 if (context()) | 246 if (context()) |
247 context()->fireCompletionEvent(); | 247 context()->fireCompletionEvent(); |
248 } | 248 } |
249 | 249 |
250 bool OfflineAudioDestinationHandler::renderIfNotSuspended( | 250 bool OfflineAudioDestinationHandler::renderIfNotSuspended( |
251 AudioBus* sourceBus, | 251 AudioBus* sourceBus, |
252 AudioBus* destinationBus, | 252 AudioBus* destinationBus, |
253 size_t numberOfFrames) { | 253 size_t numberOfFrames) { |
254 // We don't want denormals slowing down any of the audio processing | 254 // We don't want denormals slowing down any of the audio processing |
255 // since they can very seriously hurt performance. | 255 // since they can very seriously hurt performance. |
256 // This will take care of all AudioNodes because they all process within this
scope. | 256 // This will take care of all AudioNodes because they all process within this |
| 257 // scope. |
257 DenormalDisabler denormalDisabler; | 258 DenormalDisabler denormalDisabler; |
258 | 259 |
259 // Need to check if the context actually alive. Otherwise the subsequent | 260 // Need to check if the context actually alive. Otherwise the subsequent |
260 // steps will fail. If the context is not alive somehow, return immediately | 261 // steps will fail. If the context is not alive somehow, return immediately |
261 // and do nothing. | 262 // and do nothing. |
262 // | 263 // |
263 // TODO(hongchan): because the context can go away while rendering, so this | 264 // TODO(hongchan): because the context can go away while rendering, so this |
264 // check cannot guarantee the safe execution of the following steps. | 265 // check cannot guarantee the safe execution of the following steps. |
265 DCHECK(context()); | 266 DCHECK(context()); |
266 if (!context()) | 267 if (!context()) |
(...skipping 19 matching lines...) Expand all Loading... |
286 | 287 |
287 // Prepare the local audio input provider for this render quantum. | 288 // Prepare the local audio input provider for this render quantum. |
288 if (sourceBus) | 289 if (sourceBus) |
289 m_localAudioInputProvider.set(sourceBus); | 290 m_localAudioInputProvider.set(sourceBus); |
290 | 291 |
291 DCHECK_GE(numberOfInputs(), 1u); | 292 DCHECK_GE(numberOfInputs(), 1u); |
292 if (numberOfInputs() < 1) { | 293 if (numberOfInputs() < 1) { |
293 destinationBus->zero(); | 294 destinationBus->zero(); |
294 return false; | 295 return false; |
295 } | 296 } |
296 // This will cause the node(s) connected to us to process, which in turn will
pull on their input(s), | 297 // This will cause the node(s) connected to us to process, which in turn will |
297 // all the way backwards through the rendering graph. | 298 // pull on their input(s), all the way backwards through the rendering graph. |
298 AudioBus* renderedBus = input(0).pull(destinationBus, numberOfFrames); | 299 AudioBus* renderedBus = input(0).pull(destinationBus, numberOfFrames); |
299 | 300 |
300 if (!renderedBus) { | 301 if (!renderedBus) { |
301 destinationBus->zero(); | 302 destinationBus->zero(); |
302 } else if (renderedBus != destinationBus) { | 303 } else if (renderedBus != destinationBus) { |
303 // in-place processing was not possible - so copy | 304 // in-place processing was not possible - so copy |
304 destinationBus->copyFrom(*renderedBus); | 305 destinationBus->copyFrom(*renderedBus); |
305 } | 306 } |
306 | 307 |
307 // Process nodes which need a little extra help because they are not connected
to anything, but still need to process. | 308 // Process nodes which need a little extra help because they are not connected |
| 309 // to anything, but still need to process. |
308 context()->deferredTaskHandler().processAutomaticPullNodes(numberOfFrames); | 310 context()->deferredTaskHandler().processAutomaticPullNodes(numberOfFrames); |
309 | 311 |
310 // Let the context take care of any business at the end of each render quantum
. | 312 // Let the context take care of any business at the end of each render |
| 313 // quantum. |
311 context()->handlePostOfflineRenderTasks(); | 314 context()->handlePostOfflineRenderTasks(); |
312 | 315 |
313 // Advance current sample-frame. | 316 // Advance current sample-frame. |
314 size_t newSampleFrame = m_currentSampleFrame + numberOfFrames; | 317 size_t newSampleFrame = m_currentSampleFrame + numberOfFrames; |
315 releaseStore(&m_currentSampleFrame, newSampleFrame); | 318 releaseStore(&m_currentSampleFrame, newSampleFrame); |
316 | 319 |
317 return false; | 320 return false; |
318 } | 321 } |
319 | 322 |
320 // ---------------------------------------------------------------- | 323 // ---------------------------------------------------------------- |
321 | 324 |
322 OfflineAudioDestinationNode::OfflineAudioDestinationNode( | 325 OfflineAudioDestinationNode::OfflineAudioDestinationNode( |
323 BaseAudioContext& context, | 326 BaseAudioContext& context, |
324 AudioBuffer* renderTarget) | 327 AudioBuffer* renderTarget) |
325 : AudioDestinationNode(context) { | 328 : AudioDestinationNode(context) { |
326 setHandler(OfflineAudioDestinationHandler::create(*this, renderTarget)); | 329 setHandler(OfflineAudioDestinationHandler::create(*this, renderTarget)); |
327 } | 330 } |
328 | 331 |
329 OfflineAudioDestinationNode* OfflineAudioDestinationNode::create( | 332 OfflineAudioDestinationNode* OfflineAudioDestinationNode::create( |
330 BaseAudioContext* context, | 333 BaseAudioContext* context, |
331 AudioBuffer* renderTarget) { | 334 AudioBuffer* renderTarget) { |
332 return new OfflineAudioDestinationNode(*context, renderTarget); | 335 return new OfflineAudioDestinationNode(*context, renderTarget); |
333 } | 336 } |
334 | 337 |
335 } // namespace blink | 338 } // namespace blink |
OLD | NEW |