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

Side by Side Diff: media/audio/audio_output_controller.cc

Issue 9580038: Convert uses of int ms to TimeDelta in media/audio. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 9 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
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/audio/audio_output_controller.h" 5 #include "media/audio/audio_output_controller.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/synchronization/waitable_event.h" 10 #include "base/synchronization/waitable_event.h"
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 155
156 // Cannot start stream immediately, should give renderer some time 156 // Cannot start stream immediately, should give renderer some time
157 // to deliver data. 157 // to deliver data.
158 // TODO(vrk): The polling here and in WaitTillDataReady() is pretty clunky. 158 // TODO(vrk): The polling here and in WaitTillDataReady() is pretty clunky.
159 // Refine the API such that polling is no longer needed. (crbug.com/112196) 159 // Refine the API such that polling is no longer needed. (crbug.com/112196)
160 number_polling_attempts_left_ = kPollNumAttempts; 160 number_polling_attempts_left_ = kPollNumAttempts;
161 message_loop_->PostDelayedTask( 161 message_loop_->PostDelayedTask(
162 FROM_HERE, 162 FROM_HERE,
163 base::Bind(&AudioOutputController::PollAndStartIfDataReady, 163 base::Bind(&AudioOutputController::PollAndStartIfDataReady,
164 weak_this_.GetWeakPtr()), 164 weak_this_.GetWeakPtr()),
165 kPollPauseInMilliseconds); 165 base::TimeDelta::FromMilliseconds(kPollPauseInMilliseconds));
166 } 166 }
167 167
168 void AudioOutputController::PollAndStartIfDataReady() { 168 void AudioOutputController::PollAndStartIfDataReady() {
169 DCHECK(message_loop_->BelongsToCurrentThread()); 169 DCHECK(message_loop_->BelongsToCurrentThread());
170 170
171 // Being paranoid: do nothing if state unexpectedly changed. 171 // Being paranoid: do nothing if state unexpectedly changed.
172 if ((state_ != kStarting) && (state_ != kPausedWhenStarting)) 172 if ((state_ != kStarting) && (state_ != kPausedWhenStarting))
173 return; 173 return;
174 174
175 bool pausing = (state_ == kPausedWhenStarting); 175 bool pausing = (state_ == kPausedWhenStarting);
176 // If we are ready to start the stream, start it. 176 // If we are ready to start the stream, start it.
177 // Of course we may have to stop it immediately... 177 // Of course we may have to stop it immediately...
178 if (--number_polling_attempts_left_ == 0 || 178 if (--number_polling_attempts_left_ == 0 ||
179 pausing || 179 pausing ||
180 sync_reader_->DataReady()) { 180 sync_reader_->DataReady()) {
181 StartStream(); 181 StartStream();
182 if (pausing) { 182 if (pausing) {
183 DoPause(); 183 DoPause();
184 } 184 }
185 } else { 185 } else {
186 message_loop_->PostDelayedTask( 186 message_loop_->PostDelayedTask(
187 FROM_HERE, 187 FROM_HERE,
188 base::Bind(&AudioOutputController::PollAndStartIfDataReady, 188 base::Bind(&AudioOutputController::PollAndStartIfDataReady,
189 weak_this_.GetWeakPtr()), 189 weak_this_.GetWeakPtr()),
190 kPollPauseInMilliseconds); 190 base::TimeDelta::FromMilliseconds(kPollPauseInMilliseconds));
191 } 191 }
192 } 192 }
193 193
194 void AudioOutputController::StartStream() { 194 void AudioOutputController::StartStream() {
195 DCHECK(message_loop_->BelongsToCurrentThread()); 195 DCHECK(message_loop_->BelongsToCurrentThread());
196 state_ = kPlaying; 196 state_ = kPlaying;
197 197
198 // We start the AudioOutputStream lazily. 198 // We start the AudioOutputStream lazily.
199 stream_->Start(this); 199 stream_->Start(this);
200 200
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 stream_ = NULL; 326 stream_ = NULL;
327 weak_this_.InvalidateWeakPtrs(); 327 weak_this_.InvalidateWeakPtrs();
328 } 328 }
329 329
330 // Should be last in the method, do not touch "this" from here on. 330 // Should be last in the method, do not touch "this" from here on.
331 if (done != NULL) 331 if (done != NULL)
332 done->Signal(); 332 done->Signal();
333 } 333 }
334 334
335 } // namespace media 335 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_low_latency_input_output_unittest.cc ('k') | media/audio/linux/alsa_output.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698