summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
Diffstat (limited to 'media')
-rw-r--r--media/audio/linux/alsa_output.cc10
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);