Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(287)

Unified Diff: content/renderer/media/webaudiosourceprovider_impl.cc

Issue 23691033: Fix threading races on WebAudioSourceProviderImpl::provideInput (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/media/webaudiosourceprovider_impl.cc
diff --git a/content/renderer/media/webaudiosourceprovider_impl.cc b/content/renderer/media/webaudiosourceprovider_impl.cc
index b722a33af4c18e3073fcea36576f1775234a440e..52501f0f276236b109be3eba085ee63608babba6 100644
--- a/content/renderer/media/webaudiosourceprovider_impl.cc
+++ b/content/renderer/media/webaudiosourceprovider_impl.cc
@@ -87,18 +87,18 @@ void WebAudioSourceProviderImpl::setClient(
void WebAudioSourceProviderImpl::provideInput(
const WebVector<float*>& audio_data, size_t number_of_frames) {
- if (!bus_wrapper_ ||
- static_cast<size_t>(bus_wrapper_->channels()) != audio_data.size()) {
- bus_wrapper_ = media::AudioBus::CreateWrapper(audio_data.size());
- }
-
- bus_wrapper_->set_frames(number_of_frames);
- for (size_t i = 0; i < audio_data.size(); ++i)
- bus_wrapper_->SetChannelData(i, audio_data[i]);
-
// Use a try lock to avoid contention in the real-time audio thread.
AutoTryLock auto_try_lock(sink_lock_);
- if (!auto_try_lock.locked() || state_ != kPlaying) {
+ if (auto_try_lock.locked() && state_ == kPlaying) {
+ if (!bus_wrapper_ ||
+ static_cast<size_t>(bus_wrapper_->channels()) != audio_data.size()) {
+ bus_wrapper_ = media::AudioBus::CreateWrapper(audio_data.size());
+ }
+
+ bus_wrapper_->set_frames(number_of_frames);
+ for (size_t i = 0; i < audio_data.size(); ++i)
+ bus_wrapper_->SetChannelData(i, audio_data[i]);
+ } else {
// Provide silence if we failed to acquire the lock or the source is not
// running.
bus_wrapper_->Zero();
Ken Russell (switch to Gerrit) 2013/09/04 17:09:36 This looks wrong. If the trylock fails, then now,
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698