Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d4a9c960 authored by Soumya Managoli's avatar Soumya Managoli Committed by Gerrit - the friendly Code Review server
Browse files

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
parent 34b11003
Loading
Loading
Loading
Loading
+20 −9
Original line number Diff line number Diff line
/*
 * Copyright (c) 2013-2017, The Linux Foundation. All rights reserved.
 * Copyright (c) 2013-2018, The Linux Foundation. All rights reserved.
 * Not a Contribution.
 *
 * Copyright (C) 2013 The Android Open Source Project
@@ -32,11 +32,7 @@ int acdb_init(int snd_card_num)
{

    int result = -1;
    char *cvd_version = NULL;

    const char *snd_card_name = NULL;
    struct mixer *mixer = NULL;
    struct acdb_platform_data *my_data = NULL;

    if(snd_card_num < 0) {
        ALOGE("invalid sound card number");
@@ -47,7 +43,25 @@ int acdb_init(int snd_card_num)
    if (!mixer) {
        ALOGE("%s: Unable to open the mixer card: %d", __func__,
               snd_card_num);
        goto cleanup;
        return result;
    }
    result = acdb_init_v2(mixer);
    mixer_close(mixer);
    return result;
}

int acdb_init_v2(struct mixer *mixer)
{

    int result = -1;
    char *cvd_version = NULL;

    const char *snd_card_name = NULL;
    struct acdb_platform_data *my_data = NULL;

    if (!mixer) {
       ALOGE("Invalid mixer handle");
       return result;
    }

    my_data = calloc(1, sizeof(struct acdb_platform_data));
@@ -155,9 +169,6 @@ cleanup:
        free(my_data);
    }

    if (mixer)
        mixer_close(mixer);

    if (cvd_version)
        free(cvd_version);

+3 −1
Original line number Diff line number Diff line
/*
 * Copyright (c) 2013-2017, The Linux Foundation. All rights reserved.
 * Copyright (c) 2013-2018, The Linux Foundation. All rights reserved.
 * Not a Contribution.
 *
 * Copyright (C) 2013 The Android Open Source Project
@@ -33,6 +33,7 @@
#define PLATFORM_INFO_XML_PATH "/vendor/etc/audio_platform_info.xml"
#endif

struct mixer;
/* Audio calibration related functions */
typedef void (*acdb_deallocate_t)();
typedef int  (*acdb_init_t)();
@@ -68,6 +69,7 @@ struct acdb_platform_data {
};

int acdb_init(int);
int acdb_init_v2(struct mixer *);

int acdb_set_metainfo_key(void *platform, char *name, int key);
#endif //ACDB_H
+2 −0
Original line number Diff line number Diff line
@@ -638,6 +638,8 @@ void audio_extn_utils_update_stream_app_type_cfg_for_usecase(
                                  struct audio_device *adev,
                                  struct audio_usecase *usecase);
int audio_extn_utils_get_snd_card_num();
int audio_extn_utils_open_snd_mixer(struct mixer **mixer_handle);
void audio_extn_utils_close_snd_mixer(struct mixer *mixer);
bool audio_extn_is_dsp_bit_width_enforce_mode_supported(audio_output_flags_t flags);
bool audio_extn_utils_is_dolby_format(audio_format_t format);
int audio_extn_utils_get_bit_width_from_string(const char *);
+25 −3
Original line number Diff line number Diff line
@@ -2110,6 +2110,17 @@ int audio_extn_utils_compress_set_start_delay(
#define RETRY_NUMBER 40

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;
@@ -2118,6 +2129,11 @@ int audio_extn_utils_get_snd_card_num()
    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 @@ int audio_extn_utils_get_snd_card_num()
    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 @@ int audio_extn_utils_get_snd_card_num()
        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,
+4 −11
Original line number Diff line number Diff line
@@ -2215,7 +2215,7 @@ void *platform_init(struct audio_device *adev)
    const char *id_string = NULL;
    int cfg_value = -1;

    snd_card_num = audio_extn_utils_get_snd_card_num();
    snd_card_num = audio_extn_utils_open_snd_mixer(&adev->mixer);
    if(snd_card_num < 0) {
        ALOGE("%s: Unable to find correct sound card", __func__);
        return NULL;
@@ -2224,13 +2224,6 @@ void *platform_init(struct audio_device *adev)
    adev->snd_card = snd_card_num;
    ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);

    adev->mixer = mixer_open(snd_card_num);
    if (!adev->mixer) {
        ALOGE("%s: Unable to open the mixer card: %d", __func__,
               snd_card_num);
        return NULL;
    }

    snd_card_name = mixer_get_name(adev->mixer);
    ALOGD("%s: snd_card_name: %s", __func__, snd_card_name);

@@ -2260,7 +2253,7 @@ void *platform_init(struct audio_device *adev)
        ALOGE("%s: Failed to init audio route controls, aborting.",
               __func__);
        free(my_data);
        mixer_close(adev->mixer);
        audio_extn_utils_close_snd_mixer(adev->mixer);
        return NULL;
    }
    update_codec_type(snd_card_name);
@@ -2482,7 +2475,7 @@ void *platform_init(struct audio_device *adev)
            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");
@@ -2777,7 +2770,7 @@ void platform_deinit(void *platform)
    }

    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;
    }

Loading