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

Side by Side Diff: media/renderers/audio_renderer_impl.cc

Issue 2434003002: AudioRendererImpl: Fix data race. (Closed)
Patch Set: Created 4 years, 2 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "media/renderers/audio_renderer_impl.h" 5 #include "media/renderers/audio_renderer_impl.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <algorithm> 9 #include <algorithm>
10 #include <utility> 10 #include <utility>
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 // After this call, the |sink_| will not call back into |this| anymore. 96 // After this call, the |sink_| will not call back into |this| anymore.
97 sink_->Stop(); 97 sink_->Stop();
98 98
99 if (!init_cb_.is_null()) 99 if (!init_cb_.is_null())
100 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_ABORT); 100 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_ABORT);
101 } 101 }
102 102
103 void AudioRendererImpl::StartTicking() { 103 void AudioRendererImpl::StartTicking() {
104 DVLOG(1) << __func__; 104 DVLOG(1) << __func__;
105 DCHECK(task_runner_->BelongsToCurrentThread()); 105 DCHECK(task_runner_->BelongsToCurrentThread());
106
107 base::AutoLock auto_lock(lock_);
108
106 DCHECK(!rendering_); 109 DCHECK(!rendering_);
107 rendering_ = true; 110 rendering_ = true;
108 111
109 base::AutoLock auto_lock(lock_);
110 // Wait for an eventual call to SetPlaybackRate() to start rendering. 112 // Wait for an eventual call to SetPlaybackRate() to start rendering.
111 if (playback_rate_ == 0) { 113 if (playback_rate_ == 0) {
112 DCHECK(!sink_playing_); 114 DCHECK(!sink_playing_);
113 return; 115 return;
114 } 116 }
115 117
116 StartRendering_Locked(); 118 StartRendering_Locked();
117 } 119 }
118 120
119 void AudioRendererImpl::StartRendering_Locked() { 121 void AudioRendererImpl::StartRendering_Locked() {
120 DVLOG(1) << __func__; 122 DVLOG(1) << __func__;
121 DCHECK(task_runner_->BelongsToCurrentThread()); 123 DCHECK(task_runner_->BelongsToCurrentThread());
122 DCHECK_EQ(state_, kPlaying); 124 DCHECK_EQ(state_, kPlaying);
123 DCHECK(!sink_playing_); 125 DCHECK(!sink_playing_);
124 DCHECK_NE(playback_rate_, 0.0); 126 DCHECK_NE(playback_rate_, 0.0);
125 lock_.AssertAcquired(); 127 lock_.AssertAcquired();
126 128
127 sink_playing_ = true; 129 sink_playing_ = true;
128 130
129 base::AutoUnlock auto_unlock(lock_); 131 base::AutoUnlock auto_unlock(lock_);
130 sink_->Play(); 132 sink_->Play();
131 } 133 }
132 134
133 void AudioRendererImpl::StopTicking() { 135 void AudioRendererImpl::StopTicking() {
134 DVLOG(1) << __func__; 136 DVLOG(1) << __func__;
135 DCHECK(task_runner_->BelongsToCurrentThread()); 137 DCHECK(task_runner_->BelongsToCurrentThread());
138
139 base::AutoLock auto_lock(lock_);
140
136 DCHECK(rendering_); 141 DCHECK(rendering_);
137 rendering_ = false; 142 rendering_ = false;
138 143
139 base::AutoLock auto_lock(lock_);
140 // Rendering should have already been stopped with a zero playback rate. 144 // Rendering should have already been stopped with a zero playback rate.
141 if (playback_rate_ == 0) { 145 if (playback_rate_ == 0) {
142 DCHECK(!sink_playing_); 146 DCHECK(!sink_playing_);
143 return; 147 return;
144 } 148 }
145 149
146 StopRendering_Locked(); 150 StopRendering_Locked();
147 } 151 }
148 152
149 void AudioRendererImpl::StopRendering_Locked() { 153 void AudioRendererImpl::StopRendering_Locked() {
(...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 DCHECK_NE(buffering_state_, buffering_state); 977 DCHECK_NE(buffering_state_, buffering_state);
974 lock_.AssertAcquired(); 978 lock_.AssertAcquired();
975 buffering_state_ = buffering_state; 979 buffering_state_ = buffering_state;
976 980
977 task_runner_->PostTask( 981 task_runner_->PostTask(
978 FROM_HERE, base::Bind(&AudioRendererImpl::OnBufferingStateChange, 982 FROM_HERE, base::Bind(&AudioRendererImpl::OnBufferingStateChange,
979 weak_factory_.GetWeakPtr(), buffering_state_)); 983 weak_factory_.GetWeakPtr(), buffering_state_));
980 } 984 }
981 985
982 } // namespace media 986 } // namespace media
OLDNEW
« 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