| 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 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 namespace blink { | 42 namespace blink { |
| 43 | 43 |
| 44 OfflineAudioDestinationHandler::OfflineAudioDestinationHandler( | 44 OfflineAudioDestinationHandler::OfflineAudioDestinationHandler( |
| 45 AudioNode& node, | 45 AudioNode& node, |
| 46 AudioBuffer* render_target) | 46 AudioBuffer* render_target) |
| 47 : AudioDestinationHandler(node), | 47 : AudioDestinationHandler(node), |
| 48 render_target_(render_target), | 48 render_target_(render_target), |
| 49 frames_processed_(0), | 49 frames_processed_(0), |
| 50 frames_to_process_(0), | 50 frames_to_process_(0), |
| 51 is_rendering_started_(false), | 51 is_rendering_started_(false) { |
| 52 should_suspend_(false) { | |
| 53 render_bus_ = AudioBus::Create(render_target->numberOfChannels(), | 52 render_bus_ = AudioBus::Create(render_target->numberOfChannels(), |
| 54 AudioUtilities::kRenderQuantumFrames); | 53 AudioUtilities::kRenderQuantumFrames); |
| 55 frames_to_process_ = render_target_->length(); | 54 frames_to_process_ = render_target_->length(); |
| 56 | 55 |
| 57 // Node-specific defaults. | 56 // Node-specific defaults. |
| 58 channel_count_ = render_target_->numberOfChannels(); | 57 channel_count_ = render_target_->numberOfChannels(); |
| 59 SetInternalChannelCountMode(kExplicit); | 58 SetInternalChannelCountMode(kExplicit); |
| 60 SetInternalChannelInterpretation(AudioBus::kSpeakers); | 59 SetInternalChannelInterpretation(AudioBus::kSpeakers); |
| 61 } | 60 } |
| 62 | 61 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 WrapPassRefPtr(this))); | 189 WrapPassRefPtr(this))); |
| 191 return; | 190 return; |
| 192 } | 191 } |
| 193 | 192 |
| 194 number_of_channels = render_target_->numberOfChannels(); | 193 number_of_channels = render_target_->numberOfChannels(); |
| 195 destinations.ReserveInitialCapacity(number_of_channels); | 194 destinations.ReserveInitialCapacity(number_of_channels); |
| 196 for (unsigned i = 0; i < number_of_channels; ++i) | 195 for (unsigned i = 0; i < number_of_channels; ++i) |
| 197 destinations.push_back(render_target_->getChannelData(i).View()->Data()); | 196 destinations.push_back(render_target_->getChannelData(i).View()->Data()); |
| 198 } | 197 } |
| 199 | 198 |
| 200 // Reset the suspend flag. | |
| 201 should_suspend_ = false; | |
| 202 | |
| 203 // If there is more to process and there is no suspension at the moment, | 199 // If there is more to process and there is no suspension at the moment, |
| 204 // do continue to render quanta. Then calling OfflineAudioContext.resume() | 200 // do continue to render quanta. Then calling OfflineAudioContext.resume() |
| 205 // will pick up the render loop again from where it was suspended. | 201 // will pick up the render loop again from where it was suspended. |
| 206 while (frames_to_process_ > 0 && !should_suspend_) { | 202 while (frames_to_process_ > 0) { |
| 207 // Suspend the rendering and update m_shouldSuspend if a scheduled | 203 // Suspend the rendering if a scheduled suspend found at the current |
| 208 // suspend found at the current sample frame. Otherwise render one | 204 // sample frame. Otherwise render one quantum. |
| 209 // quantum and return false. | 205 if (RenderIfNotSuspended(0, render_bus_.Get(), |
| 210 should_suspend_ = RenderIfNotSuspended( | 206 AudioUtilities::kRenderQuantumFrames)) |
| 211 0, render_bus_.Get(), AudioUtilities::kRenderQuantumFrames); | |
| 212 | |
| 213 if (should_suspend_) | |
| 214 return; | 207 return; |
| 215 | 208 |
| 216 size_t frames_available_to_copy = | 209 size_t frames_available_to_copy = |
| 217 std::min(frames_to_process_, | 210 std::min(frames_to_process_, |
| 218 static_cast<size_t>(AudioUtilities::kRenderQuantumFrames)); | 211 static_cast<size_t>(AudioUtilities::kRenderQuantumFrames)); |
| 219 | 212 |
| 220 for (unsigned channel_index = 0; channel_index < number_of_channels; | 213 for (unsigned channel_index = 0; channel_index < number_of_channels; |
| 221 ++channel_index) { | 214 ++channel_index) { |
| 222 const float* source = render_bus_->Channel(channel_index)->Data(); | 215 const float* source = render_bus_->Channel(channel_index)->Data(); |
| 223 memcpy(destinations[channel_index] + frames_processed_, source, | 216 memcpy(destinations[channel_index] + frames_processed_, source, |
| 224 sizeof(float) * frames_available_to_copy); | 217 sizeof(float) * frames_available_to_copy); |
| 225 } | 218 } |
| 226 | 219 |
| 227 frames_processed_ += frames_available_to_copy; | 220 frames_processed_ += frames_available_to_copy; |
| 228 | 221 |
| 229 DCHECK_GE(frames_to_process_, frames_available_to_copy); | 222 DCHECK_GE(frames_to_process_, frames_available_to_copy); |
| 230 frames_to_process_ -= frames_available_to_copy; | 223 frames_to_process_ -= frames_available_to_copy; |
| 231 } | 224 } |
| 232 | 225 |
| 233 // Finish up the rendering loop if there is no more to process. | 226 DCHECK_EQ(frames_to_process_, 0u); |
| 234 if (!frames_to_process_) | 227 FinishOfflineRendering(); |
| 235 FinishOfflineRendering(); | |
| 236 } | 228 } |
| 237 | 229 |
| 238 void OfflineAudioDestinationHandler::SuspendOfflineRendering() { | 230 void OfflineAudioDestinationHandler::SuspendOfflineRendering() { |
| 239 DCHECK(!IsMainThread()); | 231 DCHECK(!IsMainThread()); |
| 240 | 232 |
| 241 // The actual rendering has been suspended. Notify the context. | 233 // The actual rendering has been suspended. Notify the context. |
| 242 if (Context()->GetExecutionContext()) { | 234 if (Context()->GetExecutionContext()) { |
| 243 TaskRunnerHelper::Get(TaskType::kMediaElementEvent, | 235 TaskRunnerHelper::Get(TaskType::kMediaElementEvent, |
| 244 Context()->GetExecutionContext()) | 236 Context()->GetExecutionContext()) |
| 245 ->PostTask(BLINK_FROM_HERE, | 237 ->PostTask(BLINK_FROM_HERE, |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 SetHandler(OfflineAudioDestinationHandler::Create(*this, render_target)); | 356 SetHandler(OfflineAudioDestinationHandler::Create(*this, render_target)); |
| 365 } | 357 } |
| 366 | 358 |
| 367 OfflineAudioDestinationNode* OfflineAudioDestinationNode::Create( | 359 OfflineAudioDestinationNode* OfflineAudioDestinationNode::Create( |
| 368 BaseAudioContext* context, | 360 BaseAudioContext* context, |
| 369 AudioBuffer* render_target) { | 361 AudioBuffer* render_target) { |
| 370 return new OfflineAudioDestinationNode(*context, render_target); | 362 return new OfflineAudioDestinationNode(*context, render_target); |
| 371 } | 363 } |
| 372 | 364 |
| 373 } // namespace blink | 365 } // namespace blink |
| OLD | NEW |