Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 306 AllowEntryToOnMoreIOData(); | 306 AllowEntryToOnMoreIOData(); |
| 307 return frames; | 307 return frames; |
| 308 } | 308 } |
| 309 | 309 |
| 310 void AudioOutputController::WaitTillDataReady() { | 310 void AudioOutputController::WaitTillDataReady() { |
| 311 // Most of the time the data is ready already. | 311 // Most of the time the data is ready already. |
| 312 if (sync_reader_->DataReady()) | 312 if (sync_reader_->DataReady()) |
| 313 return; | 313 return; |
| 314 | 314 |
| 315 base::TimeTicks start = base::TimeTicks::Now(); | 315 base::TimeTicks start = base::TimeTicks::Now(); |
| 316 const base::TimeDelta kMaxWait = base::TimeDelta::FromMilliseconds(20); | |
| 316 #if defined(OS_WIN) | 317 #if defined(OS_WIN) |
| 317 // Wait for up to 683ms for DataReady(). 683ms was chosen because it's larger | 318 // Sleep(0) on windows lets the other threads run. |
| 318 // than the playback time of the WaveOut buffer size using the minimum | |
| 319 // supported sample rate: 2048 / 3000 = ~683ms. | |
| 320 // TODO(davemoore): We think this can be reduced to 20ms based on | |
| 321 // http://crrev.com/180102 but will do that in separate cl for mergability. | |
| 322 const base::TimeDelta kMaxWait = base::TimeDelta::FromMilliseconds(683); | |
| 323 const base::TimeDelta kSleep = base::TimeDelta::FromMilliseconds(0); | 319 const base::TimeDelta kSleep = base::TimeDelta::FromMilliseconds(0); |
| 324 #else | 320 #else |
| 325 const base::TimeDelta kMaxWait = base::TimeDelta::FromMilliseconds(20); | |
| 326 // We want to sleep for a bit here, as otherwise a backgrounded renderer won't | 321 // We want to sleep for a bit here, as otherwise a backgrounded renderer won't |
| 327 // get enough cpu to send the data and the high priority thread in the browser | 322 // get enough cpu to send the data and the high priority thread in the browser |
| 328 // will use up a core causing even more skips. | 323 // will use up a core causing even more skips. |
| 329 const base::TimeDelta kSleep = base::TimeDelta::FromMilliseconds(2); | 324 const base::TimeDelta kSleep = base::TimeDelta::FromMilliseconds(2); |
| 330 #endif | 325 #endif |
| 331 base::TimeDelta time_since_start; | 326 base::TimeDelta time_since_start; |
| 332 do { | 327 do { |
| 333 base::PlatformThread::Sleep(kSleep); | 328 base::PlatformThread::Sleep(kSleep); |
| 334 time_since_start = base::TimeTicks::Now() - start; | 329 time_since_start = base::TimeTicks::Now() - start; |
| 335 } while (!sync_reader_->DataReady() && (time_since_start < kMaxWait)); | 330 } while (!sync_reader_->DataReady() && (time_since_start < kMaxWait)); |
| 336 UMA_HISTOGRAM_CUSTOM_TIMES("Media.AudioOutputControllerDataNotReady", | 331 UMA_HISTOGRAM_CUSTOM_TIMES("Media.AudioOutputController.WaitForDataTime", |
|
DaleCurtis
2013/05/29 21:39:06
Actually, you can revert the histogram change too.
| |
| 337 time_since_start, | 332 time_since_start, |
| 338 base::TimeDelta::FromMilliseconds(1), | 333 base::TimeDelta::FromMilliseconds(1), |
| 339 base::TimeDelta::FromMilliseconds(1000), | 334 base::TimeDelta::FromMilliseconds(1000), |
| 340 50); | 335 50); |
| 341 } | 336 } |
| 342 | 337 |
| 343 void AudioOutputController::OnError(AudioOutputStream* stream) { | 338 void AudioOutputController::OnError(AudioOutputStream* stream) { |
| 344 // Handle error on the audio controller thread. | 339 // Handle error on the audio controller thread. |
| 345 message_loop_->PostTask(FROM_HERE, base::Bind( | 340 message_loop_->PostTask(FROM_HERE, base::Bind( |
| 346 &AudioOutputController::DoReportError, this)); | 341 &AudioOutputController::DoReportError, this)); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 442 DCHECK(base::AtomicRefCountIsZero(&num_allowed_io_)); | 437 DCHECK(base::AtomicRefCountIsZero(&num_allowed_io_)); |
| 443 base::AtomicRefCountInc(&num_allowed_io_); | 438 base::AtomicRefCountInc(&num_allowed_io_); |
| 444 } | 439 } |
| 445 | 440 |
| 446 void AudioOutputController::DisallowEntryToOnMoreIOData() { | 441 void AudioOutputController::DisallowEntryToOnMoreIOData() { |
| 447 const bool is_zero = !base::AtomicRefCountDec(&num_allowed_io_); | 442 const bool is_zero = !base::AtomicRefCountDec(&num_allowed_io_); |
| 448 DCHECK(is_zero); | 443 DCHECK(is_zero); |
| 449 } | 444 } |
| 450 | 445 |
| 451 } // namespace media | 446 } // namespace media |
| OLD | NEW |