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

Commit 36f3d378 authored by Preetam Singh Ranawat's avatar Preetam Singh Ranawat
Browse files

hal: native audio backward compatibility

- all changes for native audio backward
  compatibility and related.
- add set parameters from UI
- enable dynamic device switching
- featurize the code
- various backend concurrency changes.

Change-Id: Id0f824c4b4c033f42008a4e8868652c8f6fe5c42
parent 1871ddbe
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -574,6 +574,10 @@ int audio_extn_utils_send_app_type_cfg(struct audio_usecase *usecase)
    if ((24 == usecase->stream.out->bit_width) &&
        (usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER)) {
        sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
    } else if ((snd_device != SND_DEVICE_OUT_HEADPHONES_44_1 &&
        usecase->stream.out->sample_rate == OUTPUT_SAMPLING_RATE_44100) ||
        (usecase->stream.out->sample_rate < OUTPUT_SAMPLING_RATE_44100)) {
        sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
    } else {
        sample_rate = out->app_type_cfg.sample_rate;
    }
@@ -594,6 +598,7 @@ int audio_extn_utils_send_app_type_cfg(struct audio_usecase *usecase)
        app_type_cfg[len++] = sample_rate * 4;
    else
        app_type_cfg[len++] = sample_rate;

    mixer_ctl_set_array(ctl, app_type_cfg, len);
    ALOGI("%s app_type %d, acdb_dev_id %d, sample_rate %d",
           __func__, out->app_type_cfg.app_type, acdb_dev_id, sample_rate);
+19 −18
Original line number Diff line number Diff line
@@ -582,6 +582,8 @@ static void check_usecases_codec_backend(struct audio_device *adev,
    struct audio_usecase *usecase;
    bool switch_device[AUDIO_USECASE_MAX];
    int i, num_uc_to_switch = 0;
    int backend_idx = DEFAULT_CODEC_BACKEND;
    int usecase_backend_idx = DEFAULT_CODEC_BACKEND;

    /*
     * This function is to make sure that all the usecases that are active on
@@ -598,39 +600,38 @@ static void check_usecases_codec_backend(struct audio_device *adev,
     * If there is a backend configuration change for the device when a
     * new stream starts, then ADM needs to be closed and re-opened with the new
     * configuraion. This call check if we need to re-route all the streams
     * associated with the backend. Touch tone + 24 bit playback.
     * associated with the backend. Touch tone + 24 bit + native playback.
     */
    bool force_routing = platform_check_and_set_codec_backend_cfg(adev, uc_info);

    bool force_routing = platform_check_and_set_codec_backend_cfg(adev, uc_info,
                         snd_device);
    backend_idx = platform_get_backend_index(snd_device);
    /* Disable all the usecases on the shared backend other than the
     * specified usecase.
     * For native(44.1k) usecases, we don't need this as it uses a different
     * backend, but we need to make sure that we reconfigure the backend
     * if there is bit_width change, this should not affect shared backend
     * usecases.
     */
    for (i = 0; i < AUDIO_USECASE_MAX; i++)
        switch_device[i] = false;

    list_for_each(node, &adev->usecase_list) {
        usecase = node_to_item(node, struct audio_usecase, list);

        if (usecase == uc_info)
            continue;
        usecase_backend_idx = platform_get_backend_index(usecase->out_snd_device);
        ALOGV("%s: backend_idx: %d,"
              "usecase_backend_idx: %d, curr device: %s, usecase device:"
              "%s", __func__, backend_idx, usecase_backend_idx, platform_get_snd_device_name(snd_device),
            platform_get_snd_device_name(usecase->out_snd_device));

        if (usecase->type != PCM_CAPTURE &&
                usecase != uc_info &&
                (usecase->out_snd_device != snd_device || force_routing)  &&
                usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND
                && usecase->stream.out->sample_rate != OUTPUT_SAMPLING_RATE_44100) {
            ALOGV("%s: Usecase (%s) is active on (%s) - disabling ..",
                  __func__, use_case_table[usecase->id],
                usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND &&
                usecase_backend_idx == backend_idx) {
            ALOGV("%s: Usecase (%s) is active on (%s) - disabling ..", __func__,
                  use_case_table[usecase->id],
                  platform_get_snd_device_name(usecase->out_snd_device));
            disable_audio_route(adev, usecase);
            switch_device[usecase->id] = true;
            num_uc_to_switch++;
        } else if (usecase->type == PCM_PLAYBACK &&
                  usecase->stream.out->sample_rate ==
                  OUTPUT_SAMPLING_RATE_44100 && force_routing){
           disable_audio_route(adev, usecase);
           switch_device[usecase->id] = true;
           num_uc_to_switch++;
        }
    }

+2 −0
Original line number Diff line number Diff line
@@ -309,6 +309,8 @@ struct audio_device {
    bool bt_wb_speech_enabled;

    int snd_card;
    unsigned int cur_codec_backend_samplerate;
    unsigned int cur_codec_backend_bit_width;
    void *platform;
    unsigned int offload_usecases_state;
    void *visualizer_lib;
+15 −2
Original line number Diff line number Diff line
@@ -1730,6 +1730,16 @@ int platform_get_snd_device_bit_width(snd_device_t snd_device)
    return backend_bit_width_table[snd_device];
}

int platform_set_native_support(bool codec_support __unused)
{
    return 0;
}

int platform_get_backend_index(snd_device_t snd_device __unused)
{
    return 0;
}

int platform_send_audio_calibration(void *platform, struct audio_usecase *usecase,
                                    int app_type, int sample_rate)
{
@@ -2016,12 +2026,13 @@ int platform_set_device_mute(void *platform, bool state, char *dir)
    return ret;
}

snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
snd_device_t platform_get_output_snd_device(void *platform, struct stream_out *out)
{
    struct platform_data *my_data = (struct platform_data *)platform;
    struct audio_device *adev = my_data->adev;
    audio_mode_t mode = adev->mode;
    snd_device_t snd_device = SND_DEVICE_NONE;
    audio_devices_t devices = out->devices;
#ifdef RECORD_PLAY_CONCURRENCY
    bool use_voip_out_devices = false;
    bool prop_rec_play_enabled = false;
@@ -3553,7 +3564,9 @@ bool platform_check_codec_backend_cfg(struct audio_device* adev,
    return backend_change;
}

bool platform_check_and_set_codec_backend_cfg(struct audio_device* adev, struct audio_usecase *usecase)
bool platform_check_and_set_codec_backend_cfg(struct audio_device* adev,
                                              struct audio_usecase *usecase,
                                              snd_device_t snd_device __unused)
{
    ALOGV("platform_check_and_set_codec_backend_cfg usecase = %d",usecase->id );

+8 −0
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ enum {
    SND_DEVICE_OUT_SPEAKER_REVERSE,
    SND_DEVICE_OUT_SPEAKER_WSA,
    SND_DEVICE_OUT_HEADPHONES,
    SND_DEVICE_OUT_HEADPHONES_44_1,
    SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES,
    SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1,
    SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2,
@@ -162,6 +163,13 @@ enum {
};

#define DEFAULT_OUTPUT_SAMPLING_RATE 48000
#define OUTPUT_SAMPLING_RATE_44100   44100

enum {
    DEFAULT_CODEC_BACKEND,
    HEADPHONE_44_1_BACKEND,
    MAX_CODEC_BACKENDS
};

#define ALL_SESSION_VSID                0xFFFFFFFF
#define DEFAULT_MUTE_RAMP_DURATION_MS   20
Loading