Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/media/webaudiosourceprovider_impl.h" | 5 #include "content/renderer/media/webaudiosourceprovider_impl.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "third_party/WebKit/public/web/WebAudioSourceProviderClient.h" | 10 #include "third_party/WebKit/public/web/WebAudioSourceProviderClient.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 80 sink_->SetVolume(volume_); | 80 sink_->SetVolume(volume_); |
| 81 if (state_ >= kStarted) | 81 if (state_ >= kStarted) |
| 82 sink_->Start(); | 82 sink_->Start(); |
| 83 if (state_ >= kPlaying) | 83 if (state_ >= kPlaying) |
| 84 sink_->Play(); | 84 sink_->Play(); |
| 85 } | 85 } |
| 86 } | 86 } |
| 87 | 87 |
| 88 void WebAudioSourceProviderImpl::provideInput( | 88 void WebAudioSourceProviderImpl::provideInput( |
| 89 const WebVector<float*>& audio_data, size_t number_of_frames) { | 89 const WebVector<float*>& audio_data, size_t number_of_frames) { |
| 90 if (!bus_wrapper_ || | |
| 91 static_cast<size_t>(bus_wrapper_->channels()) != audio_data.size()) { | |
| 92 bus_wrapper_ = media::AudioBus::CreateWrapper(audio_data.size()); | |
| 93 } | |
| 94 | |
| 95 bus_wrapper_->set_frames(number_of_frames); | |
| 96 for (size_t i = 0; i < audio_data.size(); ++i) | |
| 97 bus_wrapper_->SetChannelData(i, audio_data[i]); | |
| 98 | |
| 99 // Use a try lock to avoid contention in the real-time audio thread. | 90 // Use a try lock to avoid contention in the real-time audio thread. |
| 100 AutoTryLock auto_try_lock(sink_lock_); | 91 AutoTryLock auto_try_lock(sink_lock_); |
| 101 if (!auto_try_lock.locked() || state_ != kPlaying) { | 92 if (auto_try_lock.locked() && state_ == kPlaying) { |
| 93 if (!bus_wrapper_ || | |
| 94 static_cast<size_t>(bus_wrapper_->channels()) != audio_data.size()) { | |
| 95 bus_wrapper_ = media::AudioBus::CreateWrapper(audio_data.size()); | |
| 96 } | |
| 97 | |
| 98 bus_wrapper_->set_frames(number_of_frames); | |
| 99 for (size_t i = 0; i < audio_data.size(); ++i) | |
| 100 bus_wrapper_->SetChannelData(i, audio_data[i]); | |
| 101 } else { | |
| 102 // Provide silence if we failed to acquire the lock or the source is not | 102 // Provide silence if we failed to acquire the lock or the source is not |
| 103 // running. | 103 // running. |
| 104 bus_wrapper_->Zero(); | 104 bus_wrapper_->Zero(); |
|
Ken Russell (switch to Gerrit)
2013/09/04 17:09:36
This looks wrong. If the trylock fails, then now,
| |
| 105 return; | 105 return; |
| 106 } | 106 } |
| 107 | 107 |
| 108 DCHECK(renderer_); | 108 DCHECK(renderer_); |
| 109 DCHECK(client_); | 109 DCHECK(client_); |
| 110 DCHECK_EQ(channels_, bus_wrapper_->channels()); | 110 DCHECK_EQ(channels_, bus_wrapper_->channels()); |
| 111 renderer_->Render(bus_wrapper_.get(), 0); | 111 renderer_->Render(bus_wrapper_.get(), 0); |
| 112 bus_wrapper_->Scale(volume_); | 112 bus_wrapper_->Scale(volume_); |
| 113 } | 113 } |
| 114 | 114 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 channels_ = params.channels(); | 165 channels_ = params.channels(); |
| 166 sample_rate_ = params.sample_rate(); | 166 sample_rate_ = params.sample_rate(); |
| 167 | 167 |
| 168 if (client_) { | 168 if (client_) { |
| 169 // Inform WebKit about the audio stream format. | 169 // Inform WebKit about the audio stream format. |
| 170 client_->setFormat(channels_, sample_rate_); | 170 client_->setFormat(channels_, sample_rate_); |
| 171 } | 171 } |
| 172 } | 172 } |
| 173 | 173 |
| 174 } // namespace content | 174 } // namespace content |
| OLD | NEW |