Chromium Code Reviews| Index: content/browser/renderer_host/media/audio_sync_reader.cc |
| diff --git a/content/browser/renderer_host/media/audio_sync_reader.cc b/content/browser/renderer_host/media/audio_sync_reader.cc |
| index 9ebf5ed970e39b69fd15a062bc83429d34fd94fd..b724c64c18b3592a35c7d52afaefdaade0cc214b 100644 |
| --- a/content/browser/renderer_host/media/audio_sync_reader.cc |
| +++ b/content/browser/renderer_host/media/audio_sync_reader.cc |
| @@ -68,11 +68,15 @@ void AudioSyncReader::UpdatePendingBytes(uint32 bytes) { |
| } |
| } |
| -int AudioSyncReader::Read(AudioBus* source, AudioBus* dest) { |
| +int AudioSyncReader::Read(bool block, const AudioBus* source, AudioBus* dest) { |
| ++renderer_callback_count_; |
| - if (!DataReady()) |
| + if (!DataReady()) { |
| ++renderer_missed_callback_count_; |
| + if (block) |
| + WaitTillDataReady(); |
| + } |
| + |
| // Copy optional synchronized live audio input for consumption by renderer |
| // process. |
| if (source && input_bus_) { |
| @@ -162,4 +166,28 @@ bool AudioSyncReader::PrepareForeignSocketHandle( |
| } |
| #endif |
| +void AudioSyncReader::WaitTillDataReady() { |
| + base::TimeTicks start = base::TimeTicks::Now(); |
| + const base::TimeDelta kMaxWait = base::TimeDelta::FromMilliseconds(20); |
|
henrika (OOO until Aug 14)
2013/06/03 07:57:18
Is it OK to use hard coded values here or should w
DaleCurtis
2013/06/04 00:35:41
I think it's okay as is. davemoore@ just cleaned t
|
| +#if defined(OS_WIN) |
| + // Sleep(0) on windows lets the other threads run. |
|
henrika (OOO until Aug 14)
2013/06/03 07:57:18
nit, Windows
DaleCurtis
2013/06/04 00:35:41
Done.
|
| + const base::TimeDelta kSleep = base::TimeDelta::FromMilliseconds(0); |
| +#else |
| + // 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 (!DataReady() && time_since_start < kMaxWait); |
| + UMA_HISTOGRAM_CUSTOM_TIMES("Media.AudioOutputControllerDataNotReady", |
| + time_since_start, |
| + base::TimeDelta::FromMilliseconds(1), |
| + base::TimeDelta::FromMilliseconds(1000), |
| + 50); |
| +} |
| + |
| } // namespace content |