diff options
author | Devin Kim <dojip.kim@lge.com> | 2016-12-29 14:03:06 -0800 |
---|---|---|
committer | Zach Johnson <zachoverflow@google.com> | 2016-12-29 16:21:51 -0800 |
commit | 3927e17c7c013cd88a889fce5c906e18e8eef6d3 (patch) | |
tree | f95befe0a48ecdfef2d041119bf41928d359370e | |
parent | dc71a44c0718dcde6309364a11c136e01d37aaae (diff) | |
download | audio-3927e17c7c013cd88a889fce5c906e18e8eef6d3.tar.gz |
audio: hal: Use the elapsed time only if last_write_time_us is valid
If last_write_time_us is zero, that means the output is first one.
So we don't need to subtract the time.
Bug: 33764682
Change-Id: If4261b90dc7b05cbe973aa68a8b965990b65b28d
-rw-r--r-- | hal/audio_hw.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/hal/audio_hw.c b/hal/audio_hw.c index 19b8fbe..0a5bccb 100644 --- a/hal/audio_hw.c +++ b/hal/audio_hw.c @@ -2204,11 +2204,17 @@ static ssize_t out_write_for_no_output(struct audio_stream_out *stream, { struct stream_out *out = (struct stream_out *)stream; struct timespec t = { .tv_sec = 0, .tv_nsec = 0 }; + int64_t now; + int64_t elapsed_time_since_last_write = 0; + int64_t sleep_time; + clock_gettime(CLOCK_MONOTONIC, &t); - const int64_t now = (t.tv_sec * 1000000000LL + t.tv_nsec) / 1000; + now = (t.tv_sec * 1000000000LL + t.tv_nsec) / 1000; + lock_output_stream(out); - const int64_t elapsed_time_since_last_write = now - out->last_write_time_us; - int64_t sleep_time = bytes * 1000000LL / audio_stream_out_frame_size(stream) / + if (out->last_write_time_us) + elapsed_time_since_last_write = now - out->last_write_time_us; + sleep_time = bytes * 1000000LL / audio_stream_out_frame_size(stream) / out_get_sample_rate(&stream->common) - elapsed_time_since_last_write; if (sleep_time > 0) { usleep(sleep_time); |