hal: Fix playback mute issue in pcm offload case
- Playback mute observed in direct pcm case due to compr_start fail.
- Compress write moves stream state from setup to prepared, then
compress start moves it to running state.
- If client writes 0 bytes of data then compress write fails and hence
compress start fails. Playback start flag is set in HAL without
checking return value of compress start causing playback mute as
compress start never happens.
- Fix is to set playback start flag only if compress start is success.
Change-Id: I139ddba1cd3944aefbcf02af36f8516529b0703b
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index e6581cf..f6e11e8 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -2807,8 +2807,14 @@
if ( ret == (ssize_t)bytes && !out->non_blocking)
out->written += bytes;
- if (!out->playback_started && ret >= 0) {
- compress_start(out->compr);
+ /* Call compr start only when non-zero bytes of data is there to be rendered */
+ if (!out->playback_started && ret > 0) {
+ int status = compress_start(out->compr);
+ if (status < 0) {
+ ret = status;
+ ALOGE("%s: compr start failed with err %d", __func__, errno);
+ goto exit;
+ }
audio_extn_dts_eagle_fade(adev, true, out);
out->playback_started = 1;
out->offload_state = OFFLOAD_STATE_PLAYING;
@@ -2885,8 +2891,9 @@
out->standby = true;
}
out_standby(&out->stream.common);
- usleep((uint64_t)bytes * 1000000 / audio_stream_out_frame_size(stream) /
- out_get_sample_rate(&out->stream.common));
+ if (!(out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD))
+ usleep((uint64_t)bytes * 1000000 / audio_stream_out_frame_size(stream) /
+ out_get_sample_rate(&out->stream.common));
}
return bytes;
}