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

Commit 46c7b87a authored by Anish Kumar's avatar Anish Kumar
Browse files

hal: enable speaker protection in call usecase

Add new device voice_speaker_protected for speaker
protection in case of voice call.This device is
used to select different acdb id in case voice
speaker device is selected as 8994 device will
use mono speaker in case of voice call and stereo
speakers in normal playback.

CRs-Fixed: 713342
Change-Id: Ib4882b6a20aefcfbae4c113f6ca0ae5d6c899d28
parent 63d100d1
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -219,14 +219,14 @@ int32_t audio_extn_read_xml(struct audio_device *adev, uint32_t mixer_card,
#define audio_extn_spkr_prot_init(adev)       (0)
#define audio_extn_spkr_prot_start_processing(snd_device)    (-EINVAL)
#define audio_extn_spkr_prot_calib_cancel(adev) (0)
#define audio_extn_spkr_prot_stop_processing()     (0)
#define audio_extn_spkr_prot_stop_processing(snd_device)     (0)
#define audio_extn_spkr_prot_is_enabled() (false)
#define audio_extn_spkr_prot_get_acdb_id(snd_device)         (-EINVAL)
#define audio_extn_get_spkr_prot_snd_device(snd_device) (snd_device)
#else
void audio_extn_spkr_prot_init(void *adev);
int audio_extn_spkr_prot_start_processing(snd_device_t snd_device);
void audio_extn_spkr_prot_stop_processing();
void audio_extn_spkr_prot_stop_processing(snd_device);
bool audio_extn_spkr_prot_is_enabled();
int audio_extn_spkr_prot_get_acdb_id(snd_device_t snd_device);
int audio_extn_get_spkr_prot_snd_device(snd_device_t snd_device);
+27 −10
Original line number Diff line number Diff line
@@ -768,20 +768,34 @@ int audio_extn_spkr_prot_get_acdb_id(snd_device_t snd_device)
{
    int acdb_id;

    acdb_id = (snd_device == SND_DEVICE_OUT_SPEAKER) ?
              platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED) :
              -EINVAL;

    switch(snd_device) {
    case SND_DEVICE_OUT_SPEAKER:
        acdb_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED);
        break;
    case SND_DEVICE_OUT_VOICE_SPEAKER:
        acdb_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED);
        break;
    default:
        acdb_id = -EINVAL;
        break;
    }
    return acdb_id;
}

int audio_extn_get_spkr_prot_snd_device(snd_device_t snd_device)
{
    if ((snd_device == SND_DEVICE_OUT_SPEAKER) && handle.spkr_prot_enable)
    if (!handle.spkr_prot_enable)
        return snd_device;

    switch(snd_device) {
    case SND_DEVICE_OUT_SPEAKER:
        return SND_DEVICE_OUT_SPEAKER_PROTECTED;
    else
    case SND_DEVICE_OUT_VOICE_SPEAKER:
        return SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
    default:
        return snd_device;
    }
}

int audio_extn_spkr_prot_start_processing(snd_device_t snd_device)
{
@@ -795,12 +809,13 @@ int audio_extn_spkr_prot_start_processing(snd_device_t snd_device)
       ALOGE("%s: Invalid params", __func__);
       return -EINVAL;
    }
    snd_device = audio_extn_get_spkr_prot_snd_device(snd_device);
    spkr_prot_set_spkrstatus(true);
    uc_info_tx = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase));
    ALOGV("%s: snd_device(%d: %s)", __func__, snd_device,
         platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_PROTECTED));
           platform_get_snd_device_name(snd_device));
    audio_route_apply_and_update_path(adev->audio_route,
        platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_PROTECTED));
           platform_get_snd_device_name(snd_device));

    pthread_mutex_lock(&handle.mutex_spkr_prot);
    if (handle.spkr_processing_state == SPKR_PROCESSING_IN_IDLE) {
@@ -854,11 +869,13 @@ exit:
    return ret;
}

void audio_extn_spkr_prot_stop_processing()
void audio_extn_spkr_prot_stop_processing(snd_device_t snd_device)
{
    struct audio_usecase *uc_info_tx;
    struct audio_device *adev = handle.adev_handle;

    ALOGV("%s: Entry", __func__);
    snd_device = audio_extn_get_spkr_prot_snd_device(snd_device);
    spkr_prot_set_spkrstatus(false);
    pthread_mutex_lock(&handle.mutex_spkr_prot);
    if (adev && handle.spkr_processing_state == SPKR_PROCESSING_IN_PROGRESS) {
@@ -876,7 +893,7 @@ void audio_extn_spkr_prot_stop_processing()
    handle.spkr_processing_state = SPKR_PROCESSING_IN_IDLE;
    pthread_mutex_unlock(&handle.mutex_spkr_prot);
    audio_route_reset_and_update_path(adev->audio_route,
      platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_PROTECTED));
                                      platform_get_snd_device_name(snd_device));
    ALOGV("%s: Exit", __func__);
}

+1 −1
Original line number Diff line number Diff line
@@ -429,7 +429,7 @@ int disable_snd_device(struct audio_device *adev,
        if ((snd_device == SND_DEVICE_OUT_SPEAKER ||
            snd_device == SND_DEVICE_OUT_VOICE_SPEAKER) &&
            audio_extn_spkr_prot_is_enabled()) {
            audio_extn_spkr_prot_stop_processing();
            audio_extn_spkr_prot_stop_processing(snd_device);
        } else {
            audio_route_reset_and_update_path(adev->audio_route, device_name);
            audio_extn_dev_arbi_release(snd_device);
+8 −1
Original line number Diff line number Diff line
@@ -241,6 +241,7 @@ static const char * const device_table[SND_DEVICE_MAX] = {
    [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = "speaker-and-anc-headphones",
    [SND_DEVICE_OUT_ANC_HANDSET] = "anc-handset",
    [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
    [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",

    /* Capture sound devices */
    [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
@@ -326,7 +327,8 @@ static int acdb_device_table[SND_DEVICE_MAX] = {
    [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = 27,
    [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = 26,
    [SND_DEVICE_OUT_ANC_HANDSET] = 103,
    [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 101,
    [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
    [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,

    [SND_DEVICE_IN_HANDSET_MIC] = 4,
    [SND_DEVICE_IN_HANDSET_MIC_EXTERNAL] = 4,
@@ -418,6 +420,7 @@ static struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
    {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET)},
    {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_HANDSET)},
    {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
    {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
    {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
    {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_EXTERNAL)},
    {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
@@ -1232,6 +1235,10 @@ int platform_switch_voice_call_device_post(void *platform,
    if (my_data->acdb_send_voice_cal == NULL) {
        ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
    } else {
        if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
            audio_extn_spkr_prot_is_enabled())
            out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;

        acdb_rx_id = acdb_device_table[out_snd_device];
        acdb_tx_id = acdb_device_table[in_snd_device];

+1 −0
Original line number Diff line number Diff line
@@ -81,6 +81,7 @@ enum {
    SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET,
    SND_DEVICE_OUT_ANC_HANDSET,
    SND_DEVICE_OUT_SPEAKER_PROTECTED,
    SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED,
    SND_DEVICE_OUT_END,

    /*