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

Commit 6ebe5964 authored by Andy Hung's avatar Andy Hung
Browse files

Add AudioRecord timestamps

Bug: 13569372
Bug: 22886739
Change-Id: I695b8a31fa427c6016f4170c09329859a41f19d2
parent 295916b2
Loading
Loading
Loading
Loading
+28 −1
Original line number Diff line number Diff line
@@ -819,7 +819,7 @@ int start_input_stream(struct stream_in *in)
    ALOGV("%s: Opening PCM device card_id(%d) device_id(%d), channels %d",
          __func__, adev->snd_card, in->pcm_device_id, in->config.channels);

    unsigned int flags = PCM_IN;
    unsigned int flags = PCM_IN | PCM_MONOTONIC;
    unsigned int pcm_open_retry_count = 0;

    if (in->usecase == USECASE_AUDIO_RECORD_AFE_PROXY) {
@@ -2051,6 +2051,8 @@ exit:
        ALOGV("%s: read failed - sleeping for buffer duration", __func__);
        usleep(bytes * 1000000 / audio_stream_in_frame_size(stream) /
               in_get_sample_rate(&in->stream.common));
    } else {
        in->frames_read += bytes / audio_stream_in_frame_size(stream);
    }
    return bytes;
}
@@ -2060,6 +2062,29 @@ static uint32_t in_get_input_frames_lost(struct audio_stream_in *stream __unused
    return 0;
}

static int in_get_capture_position(const struct audio_stream_in *stream,
                                   int64_t *frames, int64_t *time)
{
    if (stream == NULL || frames == NULL || time == NULL) {
        return -EINVAL;
    }
    struct stream_in *in = (struct stream_in *)stream;
    int ret = -ENOSYS;

    lock_input_stream(in);
    if (in->pcm) {
        struct timespec timestamp;
        unsigned int avail;
        if (pcm_get_htimestamp(in->pcm, &avail, &timestamp) == 0) {
            *frames = in->frames_read + avail;
            *time = timestamp.tv_sec * 1000000000LL + timestamp.tv_nsec;
            ret = 0;
        }
    }
    pthread_mutex_unlock(&in->lock);
    return ret;
}

static int add_remove_audio_effect(const struct audio_stream *stream,
                                   effect_handle_t effect,
                                   bool enable)
@@ -2593,6 +2618,7 @@ static int adev_open_input_stream(struct audio_hw_device *dev,
    in->stream.set_gain = in_set_gain;
    in->stream.read = in_read;
    in->stream.get_input_frames_lost = in_get_input_frames_lost;
    in->stream.get_capture_position = in_get_capture_position;

    in->device = devices;
    in->source = source;
@@ -2601,6 +2627,7 @@ static int adev_open_input_stream(struct audio_hw_device *dev,
    in->channel_mask = config->channel_mask;
    in->capture_handle = handle;
    in->flags = flags;
    // in->frames_read = 0;

    /* Update config params with the requested sample rate and channels */
    if (in->device == AUDIO_DEVICE_IN_TELEPHONY_RX) {
+1 −0
Original line number Diff line number Diff line
@@ -191,6 +191,7 @@ struct stream_in {
    audio_usecase_t usecase;
    bool enable_aec;
    bool enable_ns;
    int64_t frames_read; /* total frames read, not cleared when entering standby */

    audio_io_handle_t capture_handle;
    audio_input_flags_t flags;