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

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

Issue 10399049: Replace delay loop by sleep() call. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 8 years, 7 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 | Annotate | Revision Log
« 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/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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 message_loop_->PostDelayedTask( 202 message_loop_->PostDelayedTask(
203 FROM_HERE, 203 FROM_HERE,
204 base::Bind(&AudioOutputController::PollAndStartIfDataReady, 204 base::Bind(&AudioOutputController::PollAndStartIfDataReady,
205 weak_this_.GetWeakPtr()), 205 weak_this_.GetWeakPtr()),
206 TimeDelta::FromMilliseconds(kPollPauseInMilliseconds)); 206 TimeDelta::FromMilliseconds(kPollPauseInMilliseconds));
207 } 207 }
208 } 208 }
209 209
210 void AudioOutputController::StartStream() { 210 void AudioOutputController::StartStream() {
211 DCHECK(message_loop_->BelongsToCurrentThread()); 211 DCHECK(message_loop_->BelongsToCurrentThread());
212
212 #if defined(OS_MACOSX) 213 #if defined(OS_MACOSX)
213 // HACK: workaround for crbug.com/128128. 214 // HACK: workaround for crbug.com/128128.
214 // Mac OS crashes if we start playback too soon after previous ended. 215 // Mac OS crashes if we start playback too soon after previous ended.
215 // Audio mixer contains better fix, it keeps physical stream opened for 216 // Audio mixer contains better fix, it keeps physical stream opened for
216 // some time after logical one is closed, so sequence of play / pause / play / 217 // some time after logical one is closed, so sequence of play / pause / play /
217 // pause / ... would reuse the same stream, but we need fix for M20. 218 // pause / ... would reuse the same stream, but we need fix for M20.
218 // TODO(enal): Remove after turning on mixer by default. 219 // TODO(enal): Remove after turning on mixer by default.
219 while ((Time::Now() - previous_stop_time_).InMilliseconds() < 220 int milliseconds_since_stop =
220 kMacWorkaroundInMilliseconds) { 221 (Time::Now() - previous_stop_time_).InMilliseconds();
221 base::PlatformThread::YieldCurrentThread(); 222 if (milliseconds_since_stop < kMacWorkaroundInMilliseconds) {
DaleCurtis 2012/05/16 20:41:45 Add milliseconds_since_stop >= 0 && for safety.
223 base::PlatformThread::Sleep(
224 TimeDelta::FromMilliseconds(kMacWorkaroundInMilliseconds -
225 milliseconds_since_stop));
222 } 226 }
223 #endif 227 #endif
224 228
225 state_ = kPlaying; 229 state_ = kPlaying;
226 230
227 // We start the AudioOutputStream lazily. 231 // We start the AudioOutputStream lazily.
228 stream_->Start(this); 232 stream_->Start(this);
229 233
230 // Tell the event handler that we are now playing. 234 // Tell the event handler that we are now playing.
231 handler_->OnPlaying(this); 235 handler_->OnPlaying(this);
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 stream_ = NULL; 357 stream_ = NULL;
354 weak_this_.InvalidateWeakPtrs(); 358 weak_this_.InvalidateWeakPtrs();
355 } 359 }
356 360
357 // Should be last in the method, do not touch "this" from here on. 361 // Should be last in the method, do not touch "this" from here on.
358 if (done != NULL) 362 if (done != NULL)
359 done->Signal(); 363 done->Signal();
360 } 364 }
361 365
362 } // namespace media 366 } // 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