diff options
author | davemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-13 20:49:43 +0000 |
---|---|---|
committer | davemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-13 20:49:43 +0000 |
commit | 19af39aedd2f79bc1a1008a509601eefcbd4d05b (patch) | |
tree | e6dae13c34ec197a81c6960e7d5bb63618e1754e /media/audio/audio_output_controller.cc | |
parent | a82aae6b03284ff009c1e55add8d67aba5bb16de (diff) | |
download | chromium_src-19af39aedd2f79bc1a1008a509601eefcbd4d05b.zip chromium_src-19af39aedd2f79bc1a1008a509601eefcbd4d05b.tar.gz chromium_src-19af39aedd2f79bc1a1008a509601eefcbd4d05b.tar.bz2 |
Decrease the max wait time for audio on chromeos
BUG=231975
TEST=Play audio in background tab and do something that uses
a lot of cpu in foreground. Skipping should be decreased
although it won't be eliminated.
R=dalecurtis@chromium.org, dgreid@chromium.org
Review URL: https://codereview.chromium.org/15054009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@199820 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/audio/audio_output_controller.cc')
-rw-r--r-- | media/audio/audio_output_controller.cc | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/media/audio/audio_output_controller.cc b/media/audio/audio_output_controller.cc index a56a82d..f41ed74 100644 --- a/media/audio/audio_output_controller.cc +++ b/media/audio/audio_output_controller.cc @@ -7,6 +7,7 @@ #include "base/bind.h" #include "base/debug/trace_event.h" #include "base/message_loop.h" +#include "base/metrics/histogram.h" #include "base/threading/platform_thread.h" #include "base/time.h" #include "build/build_config.h" @@ -302,15 +303,36 @@ int AudioOutputController::OnMoreIOData(AudioBus* source, } void AudioOutputController::WaitTillDataReady() { - base::Time start = base::Time::Now(); + // Most of the time the data is ready already. + if (sync_reader_->DataReady()) + return; + + base::TimeTicks start = base::TimeTicks::Now(); +#if defined(OS_WIN) // Wait for up to 683ms for DataReady(). 683ms was chosen because it's larger // than the playback time of the WaveOut buffer size using the minimum // supported sample rate: 2048 / 3000 = ~683ms. + // TODO(davemoore): We think this can be reduced to 20ms based on + // http://crrev.com/180102 but will do that in separate cl for mergability. const base::TimeDelta kMaxWait = base::TimeDelta::FromMilliseconds(683); - while (!sync_reader_->DataReady() && - ((base::Time::Now() - start) < kMaxWait)) { - base::PlatformThread::YieldCurrentThread(); - } + const base::TimeDelta kSleep = base::TimeDelta::FromMilliseconds(0); +#else + const base::TimeDelta kMaxWait = base::TimeDelta::FromMilliseconds(20); + // We want to sleep for a bit here, as otherwise a backgrounded renderer won't + // get enough cpu to send the data and the high priority thread in the browser + // will use up a core causing even more skips. + const base::TimeDelta kSleep = base::TimeDelta::FromMilliseconds(2); +#endif + base::TimeDelta time_since_start; + do { + base::PlatformThread::Sleep(kSleep); + time_since_start = base::TimeTicks::Now() - start; + } while (!sync_reader_->DataReady() && (time_since_start < kMaxWait)); + UMA_HISTOGRAM_CUSTOM_TIMES("Media.AudioOutputControllerDataNotReady", + time_since_start, + base::TimeDelta::FromMilliseconds(1), + base::TimeDelta::FromMilliseconds(1000), + 50); } void AudioOutputController::OnError(AudioOutputStream* stream) { |