diff options
author | Andy Hung <hunga@google.com> | 2016-01-15 17:46:57 -0800 |
---|---|---|
committer | Kostas Tziridis <MrKostoulhs@gmail.com> | 2016-09-30 14:10:19 -0700 |
commit | 22f5406e6c92037aa27d3aee4f76635b3a75b1a4 (patch) | |
tree | 6a3b567632dcabb9a59d4257be14c22280879329 | |
parent | dacc114ad3e165f111ed821c80a65ba03d07f0e6 (diff) | |
download | hardware_qcom_audio-22f5406e6c92037aa27d3aee4f76635b3a75b1a4.tar.gz hardware_qcom_audio-22f5406e6c92037aa27d3aee4f76635b3a75b1a4.tar.bz2 hardware_qcom_audio-22f5406e6c92037aa27d3aee4f76635b3a75b1a4.zip |
Add AudioRecord timestamps
Bug: 13569372
Bug: 22886739
Change-Id: I695b8a31fa427c6016f4170c09329859a41f19d2
-rw-r--r-- | hal/audio_hw.c | 29 | ||||
-rw-r--r-- | hal/audio_hw.h | 1 |
2 files changed, 29 insertions, 1 deletions
diff --git a/hal/audio_hw.c b/hal/audio_hw.c index e91e7c2e..a351aa75 100644 --- a/hal/audio_hw.c +++ b/hal/audio_hw.c @@ -1049,7 +1049,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_entry_count = 0; if (in->usecase == USECASE_AUDIO_RECORD_AFE_PROXY) { @@ -2462,6 +2462,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; } @@ -2471,6 +2473,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, ×tamp) == 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) @@ -3123,12 +3148,14 @@ 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; in->dev = adev; in->standby = 1; in->channel_mask = config->channel_mask; + // in->frames_read = 0; /* Update config params with the requested sample rate and channels */ in->usecase = USECASE_AUDIO_RECORD; diff --git a/hal/audio_hw.h b/hal/audio_hw.h index b9a72e10..8fe8f6f6 100644 --- a/hal/audio_hw.h +++ b/hal/audio_hw.h @@ -198,6 +198,7 @@ struct stream_in { bool enable_aec; bool enable_ns; audio_format_t format; + int64_t frames_read; /* total frames read, not cleared when entering standby */ struct audio_device *dev; }; |