diff options
| author | Christopher N. Hesse <raymanfx@gmail.com> | 2017-01-12 11:40:30 +0100 |
|---|---|---|
| committer | Christopher N. Hesse <raymanfx@gmail.com> | 2017-02-02 11:37:05 +0000 |
| commit | ce6d5afbcd00c722f4e62097ee69605052b62007 (patch) | |
| tree | b0a00267987d253c4f4d69c714a3496851abcf11 /audio | |
| parent | e6b3a3eae446b7d650926e2dd6bc63ca9a20f46f (diff) | |
| download | hardware_samsung-ce6d5afbcd00c722f4e62097ee69605052b62007.tar.gz hardware_samsung-ce6d5afbcd00c722f4e62097ee69605052b62007.tar.bz2 hardware_samsung-ce6d5afbcd00c722f4e62097ee69605052b62007.zip | |
audio: Implement get_capture_position()
Change-Id: Ib9f637d30774b2a9aa23e6958ce5465d90eae467
Diffstat (limited to 'audio')
| -rw-r--r-- | audio/audio_hw.c | 37 | ||||
| -rw-r--r-- | audio/audio_hw.h | 2 |
2 files changed, 39 insertions, 0 deletions
diff --git a/audio/audio_hw.c b/audio/audio_hw.c index 2bd2eca..0e1e18b 100644 --- a/audio/audio_hw.c +++ b/audio/audio_hw.c @@ -3435,7 +3435,13 @@ exit: // On the subsequent in_read(), we measure the elapsed time spent in // the recording thread. This is subtracted from the sleep estimate based on frames, // thereby accounting for fill in the alsa buffer during the interim. + memset(buffer, 0, bytes); + } + + if (bytes > 0) { + in->frames_read += bytes / audio_stream_in_frame_size(stream); } + return bytes; } @@ -3446,6 +3452,35 @@ static uint32_t in_get_input_frames_lost(struct audio_stream_in *stream) 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; + struct pcm_device *pcm_device; + int ret = -ENOSYS; + + pcm_device = node_to_item(list_head(&in->pcm_dev_list), + struct pcm_device, stream_list_node); + + pthread_mutex_lock(&in->lock); + if (pcm_device->pcm) { + struct timespec timestamp; + unsigned int avail; + if (pcm_get_htimestamp(pcm_device->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) @@ -4003,6 +4038,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->devices = devices; in->source = source; @@ -4013,6 +4049,7 @@ static int adev_open_input_stream(struct audio_hw_device *dev, if (config->sample_rate != CAPTURE_DEFAULT_SAMPLING_RATE) flags = flags & ~AUDIO_INPUT_FLAG_FAST; in->input_flags = flags; + // in->frames_read = 0; /* HW codec is limited to default channels. No need to update with * requested channels */ in->config = pcm_profile->config; diff --git a/audio/audio_hw.h b/audio/audio_hw.h index 6e58a11..d2c6e0f 100644 --- a/audio/audio_hw.h +++ b/audio/audio_hw.h @@ -363,6 +363,8 @@ struct stream_in { bool is_fastcapture_affinity_set; int64_t last_read_time_us; + int64_t frames_read; /* total frames read, not cleared when + entering standby */ }; struct mixer_card { |
