hal: Avoid multiple mixer open calls during init
audio_extn_utils_get_snd_card_num opens the mixer for
primary sound card. clients of this API are opening the
mixer again for the same card. Multiple mixer open calls
during HAL initialization are adding to boot up latency.
Return mixer handle as well along with the sound card
number from audio_extn_utils_open_snd_mixer. Added
close API as well to be consistent with the open API.
Retained old APIs for backward compatability with
ST HAL.
CRs-Fixed: 2205214
Change-Id: I323ee7a3c3fe446cd268b46a6e2c498467273ddb
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index 18e36d6..02bac29 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -1929,24 +1929,17 @@
const char *id_string = NULL;
int cfg_value = -1;
- adev->snd_card = audio_extn_utils_get_snd_card_num();
+ adev->snd_card = audio_extn_utils_open_snd_mixer(&adev->mixer);
if (adev->snd_card < 0) {
ALOGE("%s: Unable to find correct sound card", __func__);
return NULL;
}
ALOGD("%s: Opened sound card:%d", __func__, adev->snd_card);
- adev->mixer = mixer_open(adev->snd_card);
- if (!adev->mixer) {
- ALOGE("%s: Unable to open the mixer card: %d", __func__,
- adev->snd_card);
- return NULL;
- }
-
snd_card_name = strdup(mixer_get_name(adev->mixer));
if (!snd_card_name) {
ALOGE("failed to allocate memory for snd_card_name\n");
- mixer_close(adev->mixer);
+ audio_extn_utils_close_snd_mixer(adev->mixer);
return NULL;
}
@@ -1955,7 +1948,7 @@
ALOGE("failed to allocate platform data");
if (snd_card_name)
free(snd_card_name);
- mixer_close(adev->mixer);
+ audio_extn_utils_close_snd_mixer(adev->mixer);
return NULL;
}
@@ -1965,7 +1958,7 @@
my_data->hw_info = hw_info_init(snd_card_name);
if (!my_data->hw_info) {
ALOGE("failed to init hw_info");
- mixer_close(adev->mixer);
+ audio_extn_utils_close_snd_mixer(adev->mixer);
if (my_data)
free(my_data);
@@ -2037,7 +2030,7 @@
free(snd_card_name);
if (snd_card_name_t)
free(snd_card_name_t);
- mixer_close(adev->mixer);
+ audio_extn_utils_close_snd_mixer(adev->mixer);
return NULL;
}
@@ -2246,7 +2239,7 @@
goto acdb_init_fail;
}
- int result = acdb_init(adev->snd_card);
+ int result = acdb_init_v2(adev->mixer);
if (!result) {
my_data->is_acdb_initialized = true;
ALOGD("ACDB initialized");
@@ -2550,7 +2543,7 @@
}
if (my_data->adev->mixer) {
- mixer_close(my_data->adev->mixer);
+ audio_extn_utils_close_snd_mixer(my_data->adev->mixer);
my_data->adev->mixer = NULL;
}