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/audio_extn/utils.c b/hal/audio_extn/utils.c
index c968c56..8a585df 100755
--- a/hal/audio_extn/utils.c
+++ b/hal/audio_extn/utils.c
@@ -2111,6 +2111,17 @@
int audio_extn_utils_get_snd_card_num()
{
+ int snd_card_num = 0;
+ struct mixer *mixer = NULL;
+
+ snd_card_num = audio_extn_utils_open_snd_mixer(&mixer);
+ if (mixer)
+ mixer_close(mixer);
+ return snd_card_num;
+}
+
+int audio_extn_utils_open_snd_mixer(struct mixer **mixer_handle)
+{
void *hw_info = NULL;
struct mixer *mixer = NULL;
@@ -2118,6 +2129,11 @@
int snd_card_num = 0, min_snd_card_num = 0;
char* snd_card_name = NULL;
+ if (!mixer_handle) {
+ ALOGE("invalid mixer handle");
+ return -1;
+ }
+ *mixer_handle = NULL;
/*
* Try with all the sound cards ( 0 to 8 ) and if none of them were detected
* sleep for 1 sec and try detections with sound card 0 again.
@@ -2171,9 +2187,6 @@
if (snd_card_name)
free(snd_card_name);
- if (mixer)
- mixer_close(mixer);
-
if (hw_info)
hw_info_deinit(hw_info);
@@ -2182,9 +2195,18 @@
return -1;
}
+ if (mixer)
+ *mixer_handle = mixer;
+
return snd_card_num;
}
+void audio_extn_utils_close_snd_mixer(struct mixer *mixer)
+{
+ if (mixer)
+ mixer_close(mixer);
+}
+
#ifdef SNDRV_COMPRESS_ENABLE_ADJUST_SESSION_CLOCK
int audio_extn_utils_compress_enable_drift_correction(
struct stream_out *out,