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

Commit c4714fc6 authored by Phil Burk's avatar Phil Burk Committed by Eric Laurent
Browse files

qcom/audio/hal: add offset to MMAP time

Try to fix glitches on AAudio MMAP input on some devices.
The DSP is returning a position/time pair that is too soon.

Bug: 122680738
Test: Should see glitch.count = 0 when you run this test.
Test: adb shell aaudio_loopback -tm -s20

Change-Id: Ib4c5b773702923ef76da124a5c6f4773e004ed7e
parent 409f07c0
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -4427,6 +4427,21 @@ static int in_start(const struct audio_stream_in* stream)
    return ret;
}

// Read offset for the input positional timestamp from a property.
// This is to workaround apparent inaccuracies in the timing info that
// are causing glitches.
static int64_t in_get_mmap_time_offset() {
    // Roughly 100 usec is needed on some devices to cover inaccuracy in DSP.
    // This should be set in a property. But I cannot read the property!
    // So I am setting the offset here to 101 as a test.
    const int32_t kDefaultOffsetMicros = 101; // should be zero if no bug
    // FIXME - why is the property not being read?! The default is used.
    int32_t mmap_time_offset_micros = property_get_int32(
        "persist.audio.in_mmap_delay_micros", kDefaultOffsetMicros);
    ALOGI("in_get_mmap_time_offset set to %d micros", mmap_time_offset_micros);
    return mmap_time_offset_micros * (int64_t)1000;
}

static int in_create_mmap_buffer(const struct audio_stream_in *stream,
                                  int32_t min_size_frames,
                                  struct audio_mmap_buffer_info *info)
@@ -4507,6 +4522,8 @@ static int in_create_mmap_buffer(const struct audio_stream_in *stream,
        goto exit;
    }

    in->mmap_time_offset_nanos = in_get_mmap_time_offset();

    in->standby = false;
    ret = 0;

@@ -4550,6 +4567,8 @@ static int in_get_mmap_position(const struct audio_stream_in *stream,
        goto exit;
    }
    position->time_nanoseconds = audio_utils_ns_from_timespec(&ts);
    position->time_nanoseconds += in->mmap_time_offset_nanos;

exit:
    pthread_mutex_unlock(&in->lock);
    return ret;
+1 −0
Original line number Diff line number Diff line
@@ -286,6 +286,7 @@ struct stream_in {
    bool enable_ns;
    int64_t frames_read; /* total frames read, not cleared when entering standby */
    int64_t frames_muted; /* total frames muted, not cleared when entering standby */
    int64_t mmap_time_offset_nanos; /* fudge factor to correct inaccuracies in DSP */

    audio_io_handle_t capture_handle;
    audio_input_flags_t flags;