Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3927e17c authored by Devin Kim's avatar Devin Kim Committed by Zach Johnson
Browse files

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
parent dc71a44c
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -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);