diff options
author | enal@chromium.org <enal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-09 01:46:04 +0000 |
---|---|---|
committer | enal@chromium.org <enal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-09 01:46:04 +0000 |
commit | 552a01e6eef2a1344c0c80285732bcd0661d9868 (patch) | |
tree | 70b010f747cd6d85583a428ff2f821a7168b4d9c /media/audio/audio_output_controller.cc | |
parent | bef1ee3f79388f87c3c88ac1a726522a2b65ca36 (diff) | |
download | chromium_src-552a01e6eef2a1344c0c80285732bcd0661d9868.zip chromium_src-552a01e6eef2a1344c0c80285732bcd0661d9868.tar.gz chromium_src-552a01e6eef2a1344c0c80285732bcd0661d9868.tar.bz2 |
Implement polling for data becoming ready when starting audio stream.
Before the change we had polling for 1st buffer but not for subsequent ones. Do it in simplest possible way -- poll and sleep in the loop. It is probably not the best approach, but simplest and most reliable. We had lot of problems adding polling for 1st buffer in the existing message loop, do not want to introduce new message loop where we had not such loop before. In any case loop usually is not executed, otherwise we would have more audible glitches when starting the stream.
Windows and Mac only change, we have only single buffer on Linux.
TEST=Start playing HTML5 audio on extremely busy Win/MAC
TEST=system with single core. Before the change you will
TEST=almost always here the glitch in the beginning.
TEST=That should become much more rare now.
Review URL: http://codereview.chromium.org/8496022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@109162 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/audio/audio_output_controller.cc')
-rw-r--r-- | media/audio/audio_output_controller.cc | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/media/audio/audio_output_controller.cc b/media/audio/audio_output_controller.cc index adad10a..b83aa61 100644 --- a/media/audio/audio_output_controller.cc +++ b/media/audio/audio_output_controller.cc @@ -7,6 +7,10 @@ #include "base/bind.h" #include "base/debug/trace_event.h" #include "base/message_loop.h" +#include "base/threading/platform_thread.h" +#include "base/time.h" + +using base::Time; namespace media { @@ -359,6 +363,19 @@ uint32 AudioOutputController::OnMoreData( return size; } +void AudioOutputController::WaitTillDataReady() { + if (LowLatencyMode() && !sync_reader_->DataReady()) { + // In the different place we use different mechanism to poll, get max + // polling delay from constants used there. + const int kMaxPollingDelayMs = kPollNumAttempts * kPollPauseInMilliseconds; + Time start_time = Time::Now(); + do { + base::PlatformThread::Sleep(1); + } while (!sync_reader_->DataReady() && + (Time::Now() - start_time).InMilliseconds() < kMaxPollingDelayMs); + } +} + void AudioOutputController::OnError(AudioOutputStream* stream, int code) { // Handle error on the audio controller thread. message_loop_->PostTask(FROM_HERE, base::Bind( |