summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2017-01-23 13:30:08 +0100
committerAndreas Schneider <asn@cryptomilk.org>2017-01-23 17:24:53 +0100
commitc8c980fc788b32823024cb8fe28e1eda796a1d54 (patch)
treee65d7d11f07fc28a4cf46a533c6c4afb2a70232a
parentc60e380eb171004ab2bc9afbbc2b8369d8b14e57 (diff)
downloadandroid_device_samsung_sltexx-c8c980fc788b32823024cb8fe28e1eda796a1d54.tar.gz
android_device_samsung_sltexx-c8c980fc788b32823024cb8fe28e1eda796a1d54.tar.xz
android_device_samsung_sltexx-c8c980fc788b32823024cb8fe28e1eda796a1d54.zip
audio: Wait for audio codecs to turn off
-rw-r--r--hal/audio/audio_hw.c73
1 files changed, 65 insertions, 8 deletions
diff --git a/hal/audio/audio_hw.c b/hal/audio/audio_hw.c
index 8e2f27c..671db33 100644
--- a/hal/audio/audio_hw.c
+++ b/hal/audio/audio_hw.c
@@ -73,6 +73,7 @@
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
#define DEVICE_DAPM_PATH "/d/asoc/Pacific WM5110 Sound/dapm"
+#define CODEC_DAPM_PATH "/d/asoc/Pacific WM5110 Sound/florida-codec/dapm"
/*
* Set the deep-buffer and low-latency output buffer sizes to
@@ -576,6 +577,62 @@ out:
}
}
+const char *audio_codecs[] = {
+ "DSP1",
+ "DSP2",
+ "DSP3",
+ "DSP4"
+};
+
+static void codecs_off(void)
+{
+ char *state = "Off";
+ bool ok = false;
+ size_t i;
+
+ for (i = 0; i < ARRAY_SIZE(audio_codecs); i++) {
+ char dapm[64] = {0};
+ int j;
+
+ snprintf(dapm, sizeof(dapm), "%s/%s", CODEC_DAPM_PATH, audio_codecs[i]);
+
+ for (j = 0; j < 20; j++) {
+ const char *p;
+ char line[32] = {0};
+ FILE *fp;
+
+ fp = fopen(dapm, "r");
+ if (fp == NULL) {
+ ALOGE("%s: Failed to open %s - %s\n",
+ __func__,
+ dapm,
+ strerror(errno));
+ break;
+ }
+
+ p = fgets(line, sizeof(line), fp);
+ fclose(fp);
+ if (p == NULL) {
+ break;
+ }
+
+ p = strstr(line, state);
+ if (p != NULL) {
+ ok = true;
+ break;
+ }
+ usleep(5);
+ }
+ }
+out:
+ if (ok) {
+ ALOGV("%s: DSPs turned off!\n", __func__);
+ } else {
+ ALOGE("%s: Failed to wait for codec to turn off", __func__);
+ usleep(50);
+ }
+}
+
static void enable_audio_route(struct audio_device *adev,
const char *mixer_path)
{
@@ -703,23 +760,23 @@ static void select_devices(struct audio_device *adev)
/*
* Disable the output and input device
*/
+ if (adev->active_output.route != NULL) {
+ disable_audio_route(adev, adev->active_output.route);
+ }
+ if (adev->active_input.route != NULL) {
+ disable_audio_route(adev, adev->active_input.route);
+ }
+ codecs_off();
+
if (adev->active_output.device != NULL) {
disable_audio_device(adev, adev->active_output.device);
output_device_off(adev->active_output.dev_id);
}
- if (adev->active_output.route != NULL) {
- disable_audio_route(adev, adev->active_output.route);
- usleep(5);
- }
if (adev->active_input.device != NULL) {
disable_audio_device(adev, adev->active_input.device);
input_devices_off();
}
- if (adev->active_input.route != NULL) {
- disable_audio_route(adev, adev->active_input.route);
- usleep(5);
- }
/*
* Already tell the modem that we are in a call. This should make it