audio: Check for stream state before checking capture position
Check if stream is in standby before calling capture position
Bug: 70527174
Test: make
Change-Id: I3543287a375a337f8b15eb59d9b97eeca9a0a1d8
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 85c886b..dba1555 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -3446,6 +3446,14 @@
int ret = -ENOSYS;
lock_input_stream(in);
+ // note: ST sessions do not close the alsa pcm driver synchronously
+ // on standby. Therefore, we may return an error even though the
+ // pcm stream is still opened.
+ if (in->standby) {
+ ALOGE_IF(in->pcm != NULL && !in->is_st_session,
+ "%s stream in standby but pcm not NULL for non ST session", __func__);
+ goto exit;
+ }
if (in->pcm) {
struct timespec timestamp;
unsigned int avail;
@@ -3455,6 +3463,7 @@
ret = 0;
}
}
+exit:
pthread_mutex_unlock(&in->lock);
return ret;
}