From 6e89524079e9c3a1037c57a99854820d88c9380b Mon Sep 17 00:00:00 2001 From: Eric Laurent Date: Thu, 5 Sep 2013 16:10:57 -0700 Subject: hal: force stop after drain. Force playback state to IDLE and send compress_stop() when drain completes to force reset driver and DSP pointers. This ensures that even if last write was partial, next write will be on a 32 byte boundary. Also do not wait for write completion if compress_write() returns an error. Bug 8174410. Change-Id: If144981c6396b24515d45b32a75ab61872a35ea2 --- hal/audio_hw.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'hal') diff --git a/hal/audio_hw.c b/hal/audio_hw.c index 73d9a3b0..852ddf68 100644 --- a/hal/audio_hw.c +++ b/hal/audio_hw.c @@ -740,8 +740,11 @@ static void *offload_thread_loop(void *context) pthread_mutex_lock(&out->lock); out->offload_thread_blocked = false; pthread_cond_signal(&out->cond); - if (send_callback) + if (send_callback) { + if (event == STREAM_CBK_EVENT_DRAIN_READY) + stop_compressed_output_l(out); out->offload_callback(event, NULL, out->offload_cookie); + } free(cmd); } @@ -1268,7 +1271,7 @@ static ssize_t out_write(struct audio_stream_out *stream, const void *buffer, { struct stream_out *out = (struct stream_out *)stream; struct audio_device *adev = out->dev; - size_t ret = 0; + ssize_t ret = 0; pthread_mutex_lock(&out->lock); if (out->standby) { @@ -1285,7 +1288,8 @@ static ssize_t out_write(struct audio_stream_out *stream, const void *buffer, if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD) { ret = compress_write(out->compr, buffer, bytes); - if (ret < bytes) { + ALOGVV("%s: writing buffer (%d bytes) to pcm device returned %d", __func__, bytes, ret); + if (ret >= 0 && ret < (ssize_t)bytes) { send_offload_cmd_l(out, OFFLOAD_CMD_WAIT_FOR_BUFFER); } if (!out->playback_started) { -- cgit v1.2.3