diff options
author | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-15 19:20:58 +0000 |
---|---|---|
committer | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-15 19:20:58 +0000 |
commit | 6ef0feb87c69e28e81dd7ca0e45dc402f181619a (patch) | |
tree | b546512382dccc9f585ce30ed14e56e57febfcbe | |
parent | c688093ff2ce1f243eca3bb7d0786986472e7b08 (diff) | |
download | chromium_src-6ef0feb87c69e28e81dd7ca0e45dc402f181619a.zip chromium_src-6ef0feb87c69e28e81dd7ca0e45dc402f181619a.tar.gz chromium_src-6ef0feb87c69e28e81dd7ca0e45dc402f181619a.tar.bz2 |
Pad time to next audio data write to compensate for nanosleep inaccuracy on linux.
Nanosleep on linux can miss its deadline by up to 10ms (according to the manpage). Pad 20ms (2x that amount) to give room for missed deadlines.
BUG=23974
TEST=listened to previously stuttering audio clip on low-end hardware.
Review URL: http://codereview.chromium.org/271081
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29163 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | media/audio/linux/alsa_output.cc | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/media/audio/linux/alsa_output.cc b/media/audio/linux/alsa_output.cc index 96a2e4b..9f3498e 100644 --- a/media/audio/linux/alsa_output.cc +++ b/media/audio/linux/alsa_output.cc @@ -88,6 +88,11 @@ // busy looping. static const int kNoDataSleepMilliseconds = 10; +// According to the linux nanosleep manpage, nanosleep on linux can miss the +// deadline by up to 10ms because the kernel timeslice is 10ms. Give a 2x +// buffer to compensate for the timeslice, and any additional slowdowns. +static const int kSleepErrorMilliseconds = 20; + // Set to 0 during debugging if you want error messages due to underrun // events or other recoverable errors. #if defined(NDEBUG) @@ -500,6 +505,11 @@ void AlsaPcmOutputStream::ScheduleNextWrite(Packet* current_packet) { int next_fill_time_ms = FramesToMillis(frames_until_empty_enough, sample_rate_); + // Adjust for timer resolution issues. + if (next_fill_time_ms > kSleepErrorMilliseconds) { + next_fill_time_ms -= kSleepErrorMilliseconds; + } + // Avoid busy looping if the data source is exhausted. if (current_packet->size == 0) { next_fill_time_ms = std::max(next_fill_time_ms, kNoDataSleepMilliseconds); |