diff options
author | Misael Lopez Cruz | 2014-02-03 16:18:59 -0600 |
---|---|---|
committer | Gerrit Code Review | 2014-02-04 16:25:17 -0600 |
commit | 247286032fe3de63fab61be0f197569e126d8a73 (patch) | |
tree | ef11146b7da8925b7c9b55e0bcb6ec19f6490120 /audio/legacy/audio_hw.c | |
parent | 6645f3bf9ecb6bcd67ea245856ab7771c77f0a45 (diff) | |
download | device-ti-jacinto6evm-247286032fe3de63fab61be0f197569e126d8a73.tar.gz device-ti-jacinto6evm-247286032fe3de63fab61be0f197569e126d8a73.tar.xz device-ti-jacinto6evm-247286032fe3de63fab61be0f197569e126d8a73.zip |
audio: Legacy: Implement get_presentation_position()
Implement the get_presentation_position() operation in the
legacy AudioHAL of jacinto6evm. get_presentation_position()
is a new stream out operation added in AudioHAL interface 3.0.
Change-Id: Ifbaac4239596d03c7880695c0ec32290dc2fa64e
Signed-off-by: Misael Lopez Cruz <misael.lopez@ti.com>
Diffstat (limited to 'audio/legacy/audio_hw.c')
-rw-r--r-- | audio/legacy/audio_hw.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/audio/legacy/audio_hw.c b/audio/legacy/audio_hw.c index 36c3d19..cef97c5 100644 --- a/audio/legacy/audio_hw.c +++ b/audio/legacy/audio_hw.c | |||
@@ -94,6 +94,7 @@ struct j6_stream_out { | |||
94 | struct pcm *pcm; | 94 | struct pcm *pcm; |
95 | pthread_mutex_t lock; | 95 | pthread_mutex_t lock; |
96 | bool standby; | 96 | bool standby; |
97 | int64_t written; /* total frames written, not cleared when entering standby */ | ||
97 | }; | 98 | }; |
98 | 99 | ||
99 | 100 | ||
@@ -588,6 +589,8 @@ static ssize_t out_write(struct audio_stream_out *stream, const void* buffer, | |||
588 | usleep(write_usecs); /* limits the rate of error messages */ | 589 | usleep(write_usecs); /* limits the rate of error messages */ |
589 | } | 590 | } |
590 | 591 | ||
592 | out->written += frames; | ||
593 | |||
591 | pthread_mutex_unlock(&out->lock); | 594 | pthread_mutex_unlock(&out->lock); |
592 | 595 | ||
593 | return bytes; | 596 | return bytes; |
@@ -615,6 +618,29 @@ static int out_get_next_write_timestamp(const struct audio_stream_out *stream, | |||
615 | return -EINVAL; | 618 | return -EINVAL; |
616 | } | 619 | } |
617 | 620 | ||
621 | static int out_get_presentation_position(const struct audio_stream_out *stream, | ||
622 | uint64_t *frames, struct timespec *timestamp) | ||
623 | { | ||
624 | struct j6_stream_out *out = (struct j6_stream_out *)(stream); | ||
625 | size_t avail; | ||
626 | int ret = -1; | ||
627 | |||
628 | pthread_mutex_lock(&out->lock); | ||
629 | |||
630 | if (pcm_get_htimestamp(out->pcm, &avail, timestamp) == 0) { | ||
631 | int64_t signed_frames = out->written - pcm_get_buffer_size(out->pcm) + avail; | ||
632 | /* It would be unusual for this value to be negative, but check just in case ... */ | ||
633 | if (signed_frames >= 0) { | ||
634 | *frames = signed_frames; | ||
635 | ret = 0; | ||
636 | } | ||
637 | } | ||
638 | |||
639 | pthread_mutex_unlock(&out->lock); | ||
640 | |||
641 | return ret; | ||
642 | } | ||
643 | |||
618 | /** audio_stream_in implementation **/ | 644 | /** audio_stream_in implementation **/ |
619 | static uint32_t in_get_sample_rate(const struct audio_stream *stream) | 645 | static uint32_t in_get_sample_rate(const struct audio_stream *stream) |
620 | { | 646 | { |
@@ -959,10 +985,12 @@ static int adev_open_output_stream(struct audio_hw_device *dev, | |||
959 | out->stream.write = out_write; | 985 | out->stream.write = out_write; |
960 | out->stream.get_render_position = out_get_render_position; | 986 | out->stream.get_render_position = out_get_render_position; |
961 | out->stream.get_next_write_timestamp = out_get_next_write_timestamp; | 987 | out->stream.get_next_write_timestamp = out_get_next_write_timestamp; |
988 | out->stream.get_presentation_position = out_get_presentation_position; | ||
962 | 989 | ||
963 | out->dev = adev; | 990 | out->dev = adev; |
964 | out->standby = true; | 991 | out->standby = true; |
965 | out->config = pcm_config_playback; | 992 | out->config = pcm_config_playback; |
993 | out->written = 0; | ||
966 | adev->out = out; | 994 | adev->out = out; |
967 | 995 | ||
968 | config->format = out_get_format(&out->stream.common); | 996 | config->format = out_get_format(&out->stream.common); |