diff options
author | Joshua Lang <joshualang@google.com> | 2016-11-05 19:01:43 -0700 |
---|---|---|
committer | Joshua Lang <joshualang@google.com> | 2017-01-19 12:46:54 -0800 |
commit | 7e000adbfa8f40ae04ea3b8c1dc1f94bb7b00865 (patch) | |
tree | b471bae9c44551d4d8f11eb9b50a2e436ca3700e /audio | |
parent | f99063d04949ca8cda9ab965787e27ae59ac4aac (diff) | |
download | device_generic_goldfish-7e000adbfa8f40ae04ea3b8c1dc1f94bb7b00865.tar.gz device_generic_goldfish-7e000adbfa8f40ae04ea3b8c1dc1f94bb7b00865.tar.bz2 device_generic_goldfish-7e000adbfa8f40ae04ea3b8c1dc1f94bb7b00865.zip |
Fix for dropped output audio frames
On every standby, some audio frames were being dropped causing the
presentation frame count to slowly drift from the written frames.
Test: Run CtsMedia module repeatedly
Bug: 31648354
Change-Id: I1075ffaad4e1baec7fdc7ebdcc9391fbb6945d28
(cherry picked from commit 818cfde6a65e7a212486092dbbcbb6f0b8de8cce)
Diffstat (limited to 'audio')
-rw-r--r-- | audio/audio_hw.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/audio/audio_hw.c b/audio/audio_hw.c index ed136d82..fd3826bd 100644 --- a/audio/audio_hw.c +++ b/audio/audio_hw.c @@ -586,9 +586,25 @@ static int out_get_render_position(const struct audio_stream_out *stream, static void do_out_standby(struct generic_stream_out *out) { + int frames_sleep = 0; + uint64_t sleep_time_us = 0; pthread_mutex_lock(&out->lock); + while (true) { + get_current_output_position(out, &out->underrun_position, NULL); + frames_sleep = out->frames_written - out->underrun_position; + + if (frames_sleep == 0) { + break; + } + + sleep_time_us = frames_sleep * 1000000LL / + out_get_sample_rate(&out->stream.common); + + pthread_mutex_unlock(&out->lock); + usleep(sleep_time_us); + pthread_mutex_lock(&out->lock); + } out->worker_standby = true; - get_current_output_position(out, &out->underrun_position, NULL); out->standby = true; pthread_mutex_unlock(&out->lock); } |