Audio: Fix for FM off/on delay post SSR
- 8-10sec delay observed when FM is turned off/on from UI post SSR with
touch tones enabled. If any new input request comes before FM is closed
post SSR, pcm driver assumes AFE is still active and starts pumping data
to AFE which is already closed due to SSR causing the delay
- Fix is to close FM session during SSR
CRs-Fixed: 673031
Change-Id: I4a55c6ca66d94e633e768b1d40584d5a5782e13e
diff --git a/hal/audio_extn/fm.c b/hal/audio_extn/fm.c
index 0c5bb07..1d1613a 100644
--- a/hal/audio_extn/fm.c
+++ b/hal/audio_extn/fm.c
@@ -51,6 +51,8 @@
struct pcm *fm_pcm_tx;
bool is_fm_running;
float fm_volume;
+ bool restart_fm;
+ int scard_state;
};
static struct fm_module fmmod = {
@@ -58,6 +60,8 @@
.fm_pcm_tx = NULL,
.fm_volume = 0,
.is_fm_running = 0,
+ .restart_fm = 0,
+ .scard_state = SND_CARD_STATE_ONLINE,
};
static int32_t fm_set_volume(struct audio_device *adev, float value)
@@ -212,7 +216,23 @@
float vol =0.0;
ALOGV("%s: enter", __func__);
+ ret = str_parms_get_str(parms, "SND_CARD_STATUS", value, sizeof(value));
+ if (ret >= 0) {
+ char *snd_card_status = value+2;
+ if (strstr(snd_card_status, "OFFLINE")) {
+ fmmod.scard_state = SND_CARD_STATE_OFFLINE;
+ }
+ else if (strstr(snd_card_status, "ONLINE")) {
+ fmmod.scard_state = SND_CARD_STATE_ONLINE;
+ }
+ }
if(fmmod.is_fm_running) {
+ if (fmmod.scard_state == SND_CARD_STATE_OFFLINE) {
+ ALOGD("sound card is OFFLINE, stop FM");
+ fm_stop(adev);
+ fmmod.restart_fm = 1;
+ }
+
ret = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_ROUTING,
value, sizeof(value));
if (ret >= 0) {
@@ -221,6 +241,11 @@
select_devices(adev, USECASE_AUDIO_PLAYBACK_FM);
}
}
+ if (fmmod.restart_fm && (fmmod.scard_state == SND_CARD_STATE_ONLINE)) {
+ ALOGD("sound card is ONLINE, restart FM");
+ fmmod.restart_fm = 0;
+ fm_start(adev);
+ }
ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_HANDLE_FM,
value, sizeof(value));