summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Hung <hunga@google.com>2015-10-14 01:18:31 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-10-14 01:18:31 +0000
commit9a2f2ef14f6655cb4f71edca2553bbad3cc62795 (patch)
treebbb92be813a00f823a3e0b9721d09778f5200580
parent7009760593d457902fed7d90fe924cf20f3d0604 (diff)
parent419c27b937b1628340985ac27f1d577e41b9a60e (diff)
downloadhardware_libhardware-9a2f2ef14f6655cb4f71edca2553bbad3cc62795.zip
hardware_libhardware-9a2f2ef14f6655cb4f71edca2553bbad3cc62795.tar.gz
hardware_libhardware-9a2f2ef14f6655cb4f71edca2553bbad3cc62795.tar.bz2
am 419c27b9: Do not reset out_get_presentation_position() to 0 on standby
* commit '419c27b937b1628340985ac27f1d577e41b9a60e': Do not reset out_get_presentation_position() to 0 on standby
-rw-r--r--modules/audio_remote_submix/audio_hw.cpp68
1 files changed, 40 insertions, 28 deletions
diff --git a/modules/audio_remote_submix/audio_hw.cpp b/modules/audio_remote_submix/audio_hw.cpp
index 20c0fab..ed3d311 100644
--- a/modules/audio_remote_submix/audio_hw.cpp
+++ b/modules/audio_remote_submix/audio_hw.cpp
@@ -179,7 +179,8 @@ struct submix_stream_out {
struct submix_audio_device *dev;
int route_handle;
bool output_standby;
- uint64_t write_counter_frames;
+ uint64_t frames_written;
+ uint64_t frames_written_since_standby;
#if LOG_STREAMS_TO_FILES
int log_fd;
#endif // LOG_STREAMS_TO_FILES
@@ -700,7 +701,7 @@ static int out_standby(struct audio_stream *stream)
pthread_mutex_lock(&rsxadev->lock);
out->output_standby = true;
- out->write_counter_frames = 0;
+ out->frames_written_since_standby = 0;
pthread_mutex_unlock(&rsxadev->lock);
@@ -855,7 +856,8 @@ static ssize_t out_write(struct audio_stream_out *stream, const void* buffer,
pthread_mutex_lock(&rsxadev->lock);
sink.clear();
if (written_frames > 0) {
- out->write_counter_frames += written_frames;
+ out->frames_written_since_standby += written_frames;
+ out->frames_written += written_frames;
}
pthread_mutex_unlock(&rsxadev->lock);
@@ -871,30 +873,31 @@ static ssize_t out_write(struct audio_stream_out *stream, const void* buffer,
static int out_get_presentation_position(const struct audio_stream_out *stream,
uint64_t *frames, struct timespec *timestamp)
{
- const submix_stream_out * out = reinterpret_cast<const struct submix_stream_out *>
- (reinterpret_cast<const uint8_t *>(stream) -
- offsetof(struct submix_stream_out, stream));
+ if (stream == NULL || frames == NULL || timestamp == NULL) {
+ return -EINVAL;
+ }
+
+ const submix_stream_out *out = audio_stream_out_get_submix_stream_out(
+ const_cast<struct audio_stream_out *>(stream));
struct submix_audio_device * const rsxadev = out->dev;
- int ret = 0;
+ int ret = -EWOULDBLOCK;
pthread_mutex_lock(&rsxadev->lock);
-
- if (frames) {
- const ssize_t frames_in_pipe =
- rsxadev->routes[out->route_handle].rsxSource->availableToRead();
- if (CC_UNLIKELY(frames_in_pipe < 0)) {
- *frames = out->write_counter_frames;
- } else {
- *frames = out->write_counter_frames > (uint64_t) frames_in_pipe ?
- out->write_counter_frames - frames_in_pipe : 0;
- }
+ const ssize_t frames_in_pipe =
+ rsxadev->routes[out->route_handle].rsxSource->availableToRead();
+ if (CC_UNLIKELY(frames_in_pipe < 0)) {
+ *frames = out->frames_written;
+ ret = 0;
+ } else if (out->frames_written >= (uint64_t)frames_in_pipe) {
+ *frames = out->frames_written - frames_in_pipe;
+ ret = 0;
}
- if (timestamp) {
+ pthread_mutex_unlock(&rsxadev->lock);
+
+ if (ret == 0) {
clock_gettime(CLOCK_MONOTONIC, timestamp);
}
- pthread_mutex_unlock(&rsxadev->lock);
-
SUBMIX_ALOGV("out_get_presentation_position() got frames=%llu timestamp sec=%llu",
frames ? *frames : -1, timestamp ? timestamp->tv_sec : -1);
@@ -904,15 +907,26 @@ static int out_get_presentation_position(const struct audio_stream_out *stream,
static int out_get_render_position(const struct audio_stream_out *stream,
uint32_t *dsp_frames)
{
- if (!dsp_frames) {
+ if (stream == NULL || dsp_frames == NULL) {
return -EINVAL;
}
- uint64_t frames = 0;
- int ret = out_get_presentation_position(stream, &frames, NULL);
- if ((ret == 0) && dsp_frames) {
- *dsp_frames = (uint32_t) frames;
+
+ const submix_stream_out *out = audio_stream_out_get_submix_stream_out(
+ const_cast<struct audio_stream_out *>(stream));
+ struct submix_audio_device * const rsxadev = out->dev;
+
+ pthread_mutex_lock(&rsxadev->lock);
+ const ssize_t frames_in_pipe =
+ rsxadev->routes[out->route_handle].rsxSource->availableToRead();
+ if (CC_UNLIKELY(frames_in_pipe < 0)) {
+ *dsp_frames = (uint32_t)out->frames_written_since_standby;
+ } else {
+ *dsp_frames = out->frames_written_since_standby > (uint64_t) frames_in_pipe ?
+ (uint32_t)(out->frames_written_since_standby - frames_in_pipe) : 0;
}
- return ret;
+ pthread_mutex_unlock(&rsxadev->lock);
+
+ return 0;
}
static int out_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
@@ -1381,8 +1395,6 @@ static int adev_open_output_stream(struct audio_hw_device *dev,
out->stream.get_next_write_timestamp = out_get_next_write_timestamp;
out->stream.get_presentation_position = out_get_presentation_position;
- out->write_counter_frames = 0;
-
#if ENABLE_RESAMPLING
// Recreate the pipe with the correct sample rate so that MonoPipe.write() rate limits
// writes correctly.