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

Commit 68a7af9b authored by Xin Li's avatar Xin Li
Browse files

Merge stage-dr1-aosp-master into stage-aosp-master

Bug: 112535855
Change-Id: I35111b64c75d8b8ff67e8b627eac8046deeeb587
parents 3084dd69 b644dc8f
Loading
Loading
Loading
Loading
+89 −46
Original line number Diff line number Diff line
@@ -159,6 +159,11 @@ typedef enum {
    IMC_ENABLE,
} imc_status_t;

typedef enum {
    MTU_SIZE,
    PEAK_BIT_RATE,
} frame_control_type_t;

/* PCM config for ABR Feedback hostless front end */
static struct pcm_config pcm_config_abr = {
    .channels = 1,
@@ -288,6 +293,17 @@ struct imc_dec_enc_info {
    uint32_t comm_instance;
};

/* Structure to control frame size of AAC encoded frames. */
struct aac_frame_size_control_t {
    /* Type of frame size control: MTU_SIZE / PEAK_BIT_RATE*/
    uint32_t ctl_type;
    /* Control value
     * MTU_SIZE: MTU size in bytes
     * PEAK_BIT_RATE: Peak bitrate in bits per second.
     */
    uint32_t ctl_value;
};

/* Structure used for ABR config of AFE encoder and decoder. */
struct abr_enc_cfg_t {
    /* Link quality level to bitrate mapping info sent to DSP. */
@@ -310,10 +326,7 @@ struct abr_dec_cfg_t {
 * These values should match with DSP interface defintion
 */

/* AAC encoder configuration structure. */
typedef struct aac_enc_cfg_t aac_enc_cfg_t;

struct aac_enc_cfg_t {
struct aac_cfg_blk_t {
    /* Encoder media format for AAC */
    uint32_t      enc_format;

@@ -333,6 +346,14 @@ struct aac_enc_cfg_t {
    uint32_t      sample_rate;
} __attribute__ ((packed));

/* AAC encoder configuration structure. */
typedef struct aac_enc_cfg_t aac_enc_cfg_t;

struct aac_enc_cfg_t {
    struct aac_cfg_blk_t aac_cfg;
    struct aac_frame_size_control_t frame_ctl;
} __attribute__ ((packed));

/* SBC encoder configuration structure. */
typedef struct sbc_enc_cfg_t sbc_enc_cfg_t;

@@ -493,6 +514,7 @@ typedef struct {
    uint32_t sampling_rate;
    uint32_t bitrate;
    uint32_t bits_per_sample;
    struct aac_frame_size_control_t frame_ctl;
} audio_aac_encoder_config;

/* Information about Bluetooth LDAC encoder configuration
@@ -807,7 +829,7 @@ static int a2dp_set_backend_cfg()
    }

    // Set Tx backend sample rate
    if (a2dp.abr_config.is_abr_enabled)
    if (a2dp.abr_config.is_abr_enabled) {
        rate_str = ABR_TX_SAMPLE_RATE;

        ALOGV("%s: set backend tx sample rate = %s", __func__, rate_str);
@@ -822,6 +844,7 @@ static int a2dp_set_backend_cfg()
                                        __func__, rate_str);
            return -ENOSYS;
        }
    }

    // Configure AFE input channels
    switch (a2dp.enc_channels) {
@@ -901,6 +924,7 @@ static int a2dp_reset_backend_cfg()
        return -ENOSYS;
    }

    if (a2dp.abr_config.is_abr_enabled) {
        ctl_sample_rate_tx = mixer_get_ctl_by_name(a2dp.adev->mixer,
                                            MIXER_SAMPLE_RATE_TX);
        if (!ctl_sample_rate_tx) {
@@ -911,6 +935,7 @@ static int a2dp_reset_backend_cfg()
            ALOGE("%s: Failed to reset Tx backend sample rate = %s", __func__, rate_str);
            return -ENOSYS;
        }
    }

    // Reset AFE input channels
    ALOGV("%s: reset AFE input channels = %s", __func__, in_channels);
@@ -1184,23 +1209,25 @@ static bool configure_aac_enc_format(audio_aac_encoder_config *aac_bt_cfg)
        goto exit;
    }
    memset(&aac_dsp_cfg, 0x0, sizeof(aac_dsp_cfg));
    aac_dsp_cfg.enc_format = ENC_MEDIA_FMT_AAC;
    aac_dsp_cfg.bit_rate = aac_bt_cfg->bitrate;
    aac_dsp_cfg.sample_rate = aac_bt_cfg->sampling_rate;
    aac_dsp_cfg.aac_cfg.enc_format = ENC_MEDIA_FMT_AAC;
    aac_dsp_cfg.aac_cfg.bit_rate = aac_bt_cfg->bitrate;
    aac_dsp_cfg.aac_cfg.sample_rate = aac_bt_cfg->sampling_rate;
    switch (aac_bt_cfg->enc_mode) {
        case 0:
            aac_dsp_cfg.enc_mode = MEDIA_FMT_AAC_AOT_LC;
            aac_dsp_cfg.aac_cfg.enc_mode = MEDIA_FMT_AAC_AOT_LC;
            break;
        case 2:
            aac_dsp_cfg.enc_mode = MEDIA_FMT_AAC_AOT_PS;
            aac_dsp_cfg.aac_cfg.enc_mode = MEDIA_FMT_AAC_AOT_PS;
            break;
        case 1:
        default:
            aac_dsp_cfg.enc_mode = MEDIA_FMT_AAC_AOT_SBR;
            aac_dsp_cfg.aac_cfg.enc_mode = MEDIA_FMT_AAC_AOT_SBR;
            break;
    }
    aac_dsp_cfg.aac_fmt_flag = aac_bt_cfg->format_flag;
    aac_dsp_cfg.channel_cfg = aac_bt_cfg->channels;
    aac_dsp_cfg.aac_cfg.aac_fmt_flag = aac_bt_cfg->format_flag;
    aac_dsp_cfg.aac_cfg.channel_cfg = aac_bt_cfg->channels;
    aac_dsp_cfg.frame_ctl.ctl_type = aac_bt_cfg->frame_ctl.ctl_type;
    aac_dsp_cfg.frame_ctl.ctl_value = aac_bt_cfg->frame_ctl.ctl_value;
    ret = mixer_ctl_set_array(ctl_enc_data, (void *)&aac_dsp_cfg,
                              sizeof(aac_dsp_cfg));
    if (ret != 0) {
@@ -1218,7 +1245,7 @@ static bool configure_aac_enc_format(audio_aac_encoder_config *aac_bt_cfg)
    a2dp.enc_sampling_rate = aac_bt_cfg->sampling_rate;
    a2dp.enc_channels = aac_bt_cfg->channels;
    ALOGV("%s: Successfully updated AAC enc format with sampling rate: %d channels:%d",
           __func__, aac_dsp_cfg.sample_rate, aac_dsp_cfg.channel_cfg);
           __func__, aac_dsp_cfg.aac_cfg.sample_rate, aac_dsp_cfg.aac_cfg.channel_cfg);
exit:
    return is_configured;
}
@@ -1457,6 +1484,15 @@ static int reset_a2dp_dec_config_params()
    return ret;
}

static void reset_a2dp_config() {
    reset_a2dp_enc_config_params();
    reset_a2dp_dec_config_params();
    a2dp_reset_backend_cfg();
    if (a2dp.abr_config.is_abr_enabled && a2dp.abr_config.abr_started)
        stop_abr();
    a2dp.abr_config.is_abr_enabled = false;
}

int audio_extn_a2dp_stop_playback()
{
    int ret = 0;
@@ -1479,12 +1515,8 @@ int audio_extn_a2dp_stop_playback()
            ALOGE("%s: stop stream to Bluetooth IPC lib failed", __func__);
        else
            ALOGV("%s: stop steam to Bluetooth IPC lib successful", __func__);
        reset_a2dp_enc_config_params();
        reset_a2dp_dec_config_params();
        a2dp_reset_backend_cfg();
        if (a2dp.abr_config.is_abr_enabled && a2dp.abr_config.abr_started)
            stop_abr();
        a2dp.abr_config.is_abr_enabled = false;
        if (!a2dp.a2dp_suspended)
            reset_a2dp_config();
        a2dp.a2dp_started = false;
    }
    ALOGD("%s: Stop A2DP playback total active sessions :%d", __func__,
@@ -1495,13 +1527,14 @@ int audio_extn_a2dp_stop_playback()
int audio_extn_a2dp_set_parameters(struct str_parms *parms, bool *reconfig)
{
     int ret = 0, val;
     int status = 0;
     char value[32] = {0};
     struct audio_usecase *uc_info;
     struct listnode *node;

     if (a2dp.is_a2dp_offload_enabled == false) {
        ALOGV("%s: No supported encoders identified,ignoring A2DP setparam", __func__);
        ret = -EINVAL;
        status = -EINVAL;
        goto param_handled;
     }

@@ -1549,8 +1582,7 @@ int audio_extn_a2dp_set_parameters(struct str_parms *parms, bool *reconfig)
                        pthread_mutex_lock(&a2dp.adev->lock);
                    }
                }
                reset_a2dp_enc_config_params();
                reset_a2dp_dec_config_params();
                reset_a2dp_config();
                if (a2dp.audio_stream_suspend) {
                   a2dp.audio_stream_suspend();
                }
@@ -1580,13 +1612,24 @@ int audio_extn_a2dp_set_parameters(struct str_parms *parms, bool *reconfig)
                if (a2dp.a2dp_total_active_session_request > 0) {
                    ALOGD("%s: Calling Bluetooth IPC lib start post suspend state", __func__);
                    if (a2dp.audio_stream_start) {
                        ret =  a2dp.audio_stream_start();
                        if (ret != 0) {
                        status =  a2dp.audio_stream_start();
                        if (status != 0) {
                            ALOGE("%s: Bluetooth controller start failed", __func__);
                            a2dp.a2dp_started = false;
                        } else {
                            if (!configure_a2dp_encoder_format()) {
                                ALOGE("%s: Encoder params configuration failed post suspend", __func__);
                                a2dp.a2dp_started = false;
                                status = -ETIMEDOUT;
                            }
                        }
                    }
                    if (a2dp.a2dp_started) {
                        a2dp_set_backend_cfg();
                        if (a2dp.abr_config.is_abr_enabled)
                            start_abr();
                    }
                }
                list_for_each(node, &a2dp.adev->usecase_list) {
                    uc_info = node_to_item(node, struct audio_usecase, list);
                    if (uc_info->type == PCM_PLAYBACK &&
@@ -1613,7 +1656,7 @@ int audio_extn_a2dp_set_parameters(struct str_parms *parms, bool *reconfig)

param_handled:
     ALOGV("%s: end of A2DP setparam", __func__);
     return ret;
     return status;
}

void audio_extn_a2dp_set_handoff_mode(bool is_on)
+3 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ void audio_extn_set_snd_card_split(const char* in_snd_card_name);
#define audio_extn_spkr_prot_stop_processing(snd_device)     (0)
#define audio_extn_spkr_prot_is_enabled() (false)
#define audio_extn_get_spkr_prot_snd_device(snd_device) (snd_device)
#define audio_extn_spkr_prot_deinit(adev)       (0)
#else
void audio_extn_spkr_prot_init(void *adev);
int audio_extn_spkr_prot_start_processing(snd_device_t snd_device);
@@ -49,6 +50,8 @@ void audio_extn_spkr_prot_stop_processing(snd_device_t snd_device);
bool audio_extn_spkr_prot_is_enabled();
int audio_extn_get_spkr_prot_snd_device(snd_device_t snd_device);
void audio_extn_spkr_prot_calib_cancel(void *adev);
void audio_extn_spkr_prot_deinit(void *adev);

#endif

#ifndef HFP_ENABLED
+106 −2
Original line number Diff line number Diff line
@@ -155,7 +155,11 @@ static struct pcm_config pcm_config_cirrus_rx = {

static struct cirrus_playback_session handle;

#ifdef CIRRUS_FACTORY_CALIBRATION
static void *audio_extn_cirrus_calibration_thread();
#else
static void *audio_extn_cirrus_config_thread();
#endif

#ifdef ENABLE_CIRRUS_DETECTION
static void *audio_extn_cirrus_failure_detect_thread();
@@ -175,11 +179,30 @@ void audio_extn_spkr_prot_init(void *adev) {

    pthread_mutex_init(&handle.fb_prot_mutex, NULL);

#ifdef CIRRUS_FACTORY_CALIBRATION
    (void)pthread_create(&handle.calibration_thread,
                (const pthread_attr_t *) NULL,
                audio_extn_cirrus_calibration_thread, &handle);
#else
    (void)pthread_create(&handle.calibration_thread,
                (const pthread_attr_t *) NULL,
                audio_extn_cirrus_config_thread, &handle);
#endif
}

void audio_extn_spkr_prot_deinit(void *adev __unused) {
    ALOGV("%s: Entry", __func__);

#ifdef ENABLE_CIRRUS_DETECTION
    pthread_join(handle.failure_detect_thread, NULL);
#endif
    pthread_join(handle.calibration_thread, NULL);
    pthread_mutex_destroy(&handle.fb_prot_mutex);

    ALOGV("%s: Exit", __func__);
}

#ifdef CIRRUS_FACTORY_CALIBRATION
static int audio_extn_cirrus_run_calibration() {
    struct audio_device *adev = handle.adev_handle;
    struct crus_sp_ioctl_header header;
@@ -282,7 +305,6 @@ static int audio_extn_cirrus_run_calibration() {
        if (ret < 0)
            goto exit;

#ifdef ENABLED_CIRRUS_WRITE_CAL_FILE
        cal_file = fopen(CRUS_CAL_FILE, "wb");
        if (cal_file == NULL) {
            ALOGE("%s: Cannot create Cirrus SP calibration file (%s)",
@@ -305,7 +327,6 @@ static int audio_extn_cirrus_run_calibration() {

        ALOGI("%s: Cirrus calibration file successfully written",
              __func__);
#endif
    }

    header.size = sizeof(header);
@@ -531,6 +552,89 @@ exit:
    return NULL;
}

#else
static void *audio_extn_cirrus_config_thread(void) {
    struct audio_device *adev = handle.adev_handle;
    struct crus_sp_ioctl_header header;
    struct cirrus_cal_result_t result;
    struct mixer_ctl *ctl_config = NULL;
    FILE *cal_file = NULL;
    int ret = 0, dev_file = -1;

    ALOGI("%s: ++", __func__);

    memset(&result, 0, sizeof(result));

    dev_file = open(CRUS_SP_FILE, O_RDWR | O_NONBLOCK);
    if (dev_file < 0) {
        ALOGE("%s: Failed to open Cirrus Playback IOCTL (%d)",
              __func__, dev_file);
        ret = -EINVAL;
        goto exit;
    }

    cal_file = fopen(CRUS_CAL_FILE, "r");
    if (cal_file) {
        ret = fread(&result, sizeof(result), 1, cal_file);

        if (ret != 1) {
            ALOGE("%s: Cirrus SP calibration file cannot be read , read size: %lu file error: %d",
                 __func__, (unsigned long)ret * sizeof(result), ferror(cal_file));
            ret = -EINVAL;
            goto exit;
        }
    }

    header.size = sizeof(header);
    header.module_id = CRUS_MODULE_ID_TX;
    header.param_id = 0;
    header.data_length = sizeof(result);
    header.data = &result;

    ret = ioctl(dev_file, CRUS_SP_IOCTL_SET_CALIB, &header);

    if (ret < 0) {
        ALOGE("%s: Cirrus SP calibration IOCTL failure", __func__);
        goto exit;
    }

    ctl_config = mixer_get_ctl_by_name(adev->mixer,
                       CRUS_SP_LOAD_CONF_MIXER);
    if (!ctl_config) {
        ALOGE("%s: Could not get ctl for mixer commands", __func__);
        ret = -EINVAL;
        goto exit;
    }

    ret = mixer_ctl_set_value(ctl_config, 0, 2);
    if (ret < 0) {
        ALOGE("%s load tx config failed", __func__);
        goto exit;
    }

    ret = mixer_ctl_set_value(ctl_config, 0, 1);
    if (ret < 0) {
        ALOGE("%s load rx config failed", __func__);
        goto exit;
    }

    ret = mixer_ctl_set_value(ctl_config, 0, 0);
    if (ret < 0) {
        ALOGE("%s set idle state failed", __func__);
        goto exit;
    }

exit:
    if (dev_file >= 0)
        close(dev_file);
    if (cal_file)
        fclose(cal_file);

    ALOGI("%s: ret: %d --", __func__, ret);
    return NULL;
}
#endif

#ifdef ENABLE_CIRRUS_DETECTION
void *audio_extn_cirrus_failure_detect_thread() {
    struct audio_device *adev = handle.adev_handle;
+18 −6
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@
#define PRESET_PATH "/vendor/etc"
#define MPS_BASE_STRING "default"
#define USER_PRESET_PATH ""
#define CONFIG_PATH "/vendor/etc/maxx_conf.ini"
#define CONFIG_BASE_STRING "maxx_conf"
#define CAL_PRESIST_STR "cal_persist"
#define CAL_SAMPLERATE_STR "cal_samplerate"

@@ -344,6 +344,7 @@ void audio_extn_ma_init(void *platform)
    int ret = 0;
    char lib_path[128] = {0};
    char mps_path[128] = {0};
    char cnf_path[128] = {0};
    struct snd_card_split *snd_split_handle = NULL;
    snd_split_handle = audio_extn_get_snd_card_split();

@@ -427,8 +428,17 @@ void audio_extn_ma_init(void *platform)
                 PRESET_PATH, MPS_BASE_STRING, snd_split_handle->form_factor);
    }

    /* get config files */
    if (snd_split_handle == NULL) {
        snprintf(cnf_path, sizeof(cnf_path), "%s/%s.ini",
                 PRESET_PATH, CONFIG_BASE_STRING);
    } else {
        snprintf(cnf_path, sizeof(cnf_path), "%s/%s_%s.ini",
                 PRESET_PATH, CONFIG_BASE_STRING, snd_split_handle->form_factor);
    }

    /* check file */
    if (access(mps_path, F_OK) < 0) {
    if (access(mps_path, R_OK) < 0) {
        ALOGW("%s: file %s isn't existed.", __func__, mps_path);
        goto error;
    } else
@@ -440,16 +450,18 @@ void audio_extn_ma_init(void *platform)
        goto error;
    }
    */
    if (access(CONFIG_PATH, F_OK) < 0) {
        ALOGW("%s: file %s isn't existed.", __func__, CONFIG_PATH);

    if (access(cnf_path, R_OK) < 0) {
        ALOGW("%s: file %s isn't existed.", __func__, cnf_path);
        goto error;
    }
    } else
        ALOGD("%s: Loading ini file: %s", __func__, cnf_path);

    /* init ma parameter */
    if (my_data->ma_param_init(&g_ma_audio_cal_handle,
                               mps_path,
                               USER_PRESET_PATH, /* unused */
                               CONFIG_PATH,
                               cnf_path,
                               &set_audio_cal)) {
        if (!g_ma_audio_cal_handle) {
            ALOGE("%s: ma parameters initialize failed", __func__);
+40 −4
Original line number Diff line number Diff line
@@ -51,6 +51,11 @@
#define MAX_CPE_SLEEP_RETRY 2
#define CPE_SLEEP_WAIT 100

#define SPLI_STATE_PATH "/proc/wcd-spi-ac/svc-state"
#define SLPI_MAGIC_NUM 0x3000
#define MAX_SLPI_SLEEP_RETRY 2
#define SLPI_SLEEP_WAIT_MS 100

#define MAX_SLEEP_RETRY 100
#define AUDIO_INIT_SLEEP_WAIT 100 /* 100 ms */

@@ -245,6 +250,31 @@ static int enum_sndcards()
    if (line)
        free(line);
    fclose(fp);

    /* Add fd to query for SLPI status */
    if (access(SPLI_STATE_PATH, R_OK) < 0) {
        ALOGV("access to %s failed: %s", SPLI_STATE_PATH, strerror(errno));
    } else {
        tries = MAX_SLPI_SLEEP_RETRY;
        ALOGV("Open %s", SPLI_STATE_PATH);
        while (tries--) {
            if ((fd = open(SPLI_STATE_PATH, O_RDONLY)) < 0) {
                ALOGW("Open %s failed %s, retry", SPLI_STATE_PATH,
                      strerror(errno));
                usleep(SLPI_SLEEP_WAIT_MS * 1000);
                continue;
            }
            break;
        }
        if (fd >= 0) {
            ret = add_new_sndcard(SLPI_MAGIC_NUM, fd);
            if (ret != 0)
                close(fd);
            else
                num_cards++;
        }
    }

    ALOGV("sndmonitor registerer num_cards %d", num_cards);
    sndmonitor.num_cards = num_cards;
    return num_cards ? 0 : -1;
@@ -383,7 +413,6 @@ bool on_sndcard_state_update(sndcard_t * s)

    ALOGV("card num %d, new state %s", s->card, rd_buf);

    bool is_cpe = (s->card >= CPE_MAGIC_NUM);
    if (strstr(rd_buf, "OFFLINE"))
        status = CARD_STATUS_OFFLINE;
    else if (strstr(rd_buf, "ONLINE"))
@@ -404,11 +433,18 @@ bool on_sndcard_state_update(sndcard_t * s)
        return -1;

    char val[32] = {0};
    // cpe actual card num is (card - MAGIC_NUM). so subtract accordingly
    snprintf(val, sizeof(val), "%d,%s", s->card - (is_cpe ? CPE_MAGIC_NUM : 0),
    bool is_cpe = ((s->card >= CPE_MAGIC_NUM) && (s->card < SLPI_MAGIC_NUM));
    bool is_slpi = (s->card == SLPI_MAGIC_NUM);
    /*
     * cpe actual card num is (card - CPE_MAGIC_NUM), so subtract accordingly.
     * SLPI actual fd num is (card - SLPI_MAGIC_NUM), so subtract accordingly.
     */
    snprintf(val, sizeof(val), "%d,%s",
        s->card - (is_cpe ? CPE_MAGIC_NUM : (is_slpi ? SLPI_MAGIC_NUM : 0)),
                 status == CARD_STATUS_ONLINE ? "ONLINE" : "OFFLINE");

    if (str_parms_add_str(params, is_cpe ? "CPE_STATUS" : "SND_CARD_STATUS",
    if (str_parms_add_str(params,
            is_cpe ? "CPE_STATUS" : (is_slpi ? "SLPI_STATUS" : "SND_CARD_STATUS"),
                          val) < 0)
        return -1;

Loading