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

Commit e60d2826 authored by Linux Build Service Account's avatar Linux Build Service Account
Browse files

Promotion of av-userspace.lnx.1.0-00022.

CRs      Change ID                                   Subject
--------------------------------------------------------------------------------------------------------------
         I970487f16af32144ec26f967e8bfcb32d44d67a4   hal: Changes to support true 44.1 Native playback

Change-Id: I1afdb8d96e65bb9720398158db1e5c262717271f
parents 8e5fb4bc e6f78cb2
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -506,7 +506,7 @@ typedef enum {
int b64decode(char *inp, int ilen, uint8_t* outp);
int b64encode(uint8_t *inp, int ilen, char* outp);
int read_line_from_file(const char *path, char *buf, size_t count);

int audio_extn_utils_get_codec_version(const char *snd_card_name, int card_num, char *codec_version);
#ifndef KPI_OPTIMIZE_ENABLED
#define audio_extn_perf_lock_init() (0)
#define audio_extn_perf_lock_acquire(handle, duration, opts, size) (0)
+45 −2
Original line number Diff line number Diff line
@@ -543,6 +543,20 @@ void audio_extn_utils_update_stream_app_type_cfg(void *platform,
    app_type_cfg->bit_width = 16;
}

static bool audio_is_this_native_usecase(struct audio_usecase *uc)
{
    bool native_usecase = false;
    struct stream_out *out = (struct stream_out*) uc->stream.out;

    if (PCM_PLAYBACK == uc->type && out != NULL &&
        NATIVE_AUDIO_MODE_INVALID != platform_get_native_support() &&
        is_offload_usecase(uc->id) &&
        (out->sample_rate == OUTPUT_SAMPLING_RATE_44100))
        native_usecase = true;

    return native_usecase;
}

int audio_extn_utils_send_app_type_cfg(struct audio_device *adev,
                                       struct audio_usecase *usecase)
{
@@ -598,8 +612,7 @@ int audio_extn_utils_send_app_type_cfg(struct audio_device *adev,
    if ((24 == usecase->stream.out->bit_width) &&
        (usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER)) {
        usecase->stream.out->app_type_cfg.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) ||
    } else if (!audio_is_this_native_usecase(usecase) ||
        (usecase->stream.out->sample_rate < OUTPUT_SAMPLING_RATE_44100)) {
        usecase->stream.out->app_type_cfg.sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
    }
@@ -621,8 +634,13 @@ int audio_extn_utils_send_app_type_cfg(struct audio_device *adev,
        app_type_cfg[len++] = sample_rate * 4;
    else
        app_type_cfg[len++] = sample_rate;

    mixer_ctl_set_array(ctl, app_type_cfg, len);
    rc = 0;
    ALOGI("%s:becf: adm: app_type %d, acdb_dev_id %d, sample_rate %d",
          __func__,
          platform_get_default_app_type_v2(adev->platform, usecase->type),
          acdb_dev_id, sample_rate);
exit_send_app_type_cfg:
    return rc;
}
@@ -813,6 +831,31 @@ done:
    return k;
}


int audio_extn_utils_get_codec_version(const char *snd_card_name,
                            int card_num,
                            char *codec_version)
{
    char procfs_path[50];
    FILE *fp;

    if (strstr(snd_card_name, "tasha")) {
        snprintf(procfs_path, sizeof(procfs_path),
                 "/proc/asound/card%d/codecs/tasha/version", card_num);
        if ((fp = fopen(procfs_path, "r")) != NULL) {
            fgets(codec_version, CODEC_VERSION_MAX_LENGTH, fp);
            fclose(fp);
        } else {
            ALOGE("%s: ERROR. cannot open %s", __func__, procfs_path);
            return -ENOENT;
        }
        ALOGD("%s: codec version %s", __func__, codec_version);
    }

    return 0;
}


#ifdef AUDIO_EXTERNAL_HDMI_ENABLED

void get_default_compressed_channel_status(
+101 −7
Original line number Diff line number Diff line
@@ -505,6 +505,7 @@ int enable_snd_device(struct audio_device *adev,
        return 0;
    }


    if (audio_extn_spkr_prot_is_enabled())
         audio_extn_spkr_prot_calib_cancel(adev);
    /* start usb playback thread */
@@ -546,6 +547,16 @@ int enable_snd_device(struct audio_device *adev,
        }
        audio_extn_dev_arbi_acquire(snd_device);
        audio_route_apply_and_update_path(adev->audio_route, device_name);

        if (SND_DEVICE_OUT_HEADPHONES == snd_device &&
            !adev->native_playback_enabled &&
            audio_is_true_native_stream_active(adev)) {
            ALOGD("%s: %d: napb: enabling native mode in hardware",
                  __func__, __LINE__);
            audio_route_apply_and_update_path(adev->audio_route,
                                              "true-native-mode");
            adev->native_playback_enabled = true;
        }
    }
    return 0;
}
@@ -592,6 +603,14 @@ int disable_snd_device(struct audio_device *adev,

        if (snd_device == SND_DEVICE_OUT_HDMI)
            adev->is_channel_status_set = false;
        else if (SND_DEVICE_OUT_HEADPHONES == snd_device &&
                 adev->native_playback_enabled) {
            ALOGD("%s: %d: napb: disabling native mode in hardware",
                  __func__, __LINE__);
            audio_route_reset_and_update_path(adev->audio_route,
                                              "true-native-mode");
            adev->native_playback_enabled = false;
        }

        audio_extn_dev_arbi_release(snd_device);
        audio_extn_sound_trigger_update_device_status(snd_device,
@@ -633,6 +652,9 @@ static void check_usecases_codec_backend(struct audio_device *adev,
     */
    bool force_routing = platform_check_and_set_codec_backend_cfg(adev, uc_info,
                         snd_device);

    ALOGD("%s:becf: force routing %d", __func__, force_routing);

    backend_idx = platform_get_backend_index(snd_device);
    /* Disable all the usecases on the shared backend other than the
     * specified usecase.
@@ -646,17 +668,19 @@ static void check_usecases_codec_backend(struct audio_device *adev,
        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),

        ALOGD("%s:becf: (%d) check_usecases backend_idx: %d,"
              "usecase_backend_idx: %d, curr device: %s, usecase device:%s",
              __func__, i, 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->out_snd_device != snd_device || force_routing)  &&
                usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND &&
                usecase_backend_idx == backend_idx) {
            ALOGD("%s: Usecase (%s) is active on (%s) - disabling ..", __func__,
                  use_case_table[usecase->id],
            ALOGD("%s:becf: check_usecases (%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;
@@ -664,6 +688,9 @@ static void check_usecases_codec_backend(struct audio_device *adev,
        }
    }

    ALOGD("%s:becf: check_usecases num.of Usecases to switch %d", __func__,
        num_uc_to_switch);

    if (num_uc_to_switch) {
        /* All streams have been de-routed. Disable the device */

@@ -690,6 +717,9 @@ static void check_usecases_codec_backend(struct audio_device *adev,
            /* Update the out_snd_device only for the usecases that are enabled here */
            if (switch_device[usecase->id] && (usecase->type != VOICE_CALL)) {
                    usecase->out_snd_device = snd_device;
                    ALOGD("%s:becf: enabling usecase (%s) on (%s)", __func__,
                      use_case_table[usecase->id],
                      platform_get_snd_device_name(usecase->out_snd_device));
                    enable_audio_route(adev, usecase);
            }
        }
@@ -834,6 +864,66 @@ struct audio_usecase *get_usecase_from_list(struct audio_device *adev,
    return NULL;
}

/*
 * is a true native playback active
 */
bool audio_is_true_native_stream_active(struct audio_device *adev)
{
    bool active = false;
    int i = 0;
    struct listnode *node;

    if (NATIVE_AUDIO_MODE_TRUE_44_1 != platform_get_native_support()) {
        ALOGV("%s:napb: not in true mode or non hdphones device",
               __func__);
        active = false;
        goto exit;
    }

    list_for_each(node, &adev->usecase_list) {
        struct audio_usecase *uc;
        uc = node_to_item(node, struct audio_usecase, list);
        struct stream_out *curr_out =
            (struct stream_out*) uc->stream.out;

        if (curr_out && PCM_PLAYBACK == uc->type) {
            ALOGD("%s:napb: (%d) (%s)id (%d) sr %d bw "
                  "(%d) device %s", __func__, i++, use_case_table[uc->id],
                  uc->id, curr_out->sample_rate,
                  curr_out->bit_width,
                  platform_get_snd_device_name(uc->out_snd_device));

            if (is_offload_usecase(uc->id) &&
                (curr_out->sample_rate == OUTPUT_SAMPLING_RATE_44100)) {
                active = true;
                ALOGD("%s:napb:native stream detected", __func__);
            }
        }
    }
exit:
    return active;
}


static bool force_device_switch(struct audio_usecase *usecase)
{
    bool ret = false;
    bool is_it_true_mode = false;

    if (is_offload_usecase(usecase->id) &&
        (usecase->stream.out) &&
        (usecase->stream.out->sample_rate == OUTPUT_SAMPLING_RATE_44100)) {
        is_it_true_mode = (NATIVE_AUDIO_MODE_TRUE_44_1 == platform_get_native_support()? true : false);
         if ((is_it_true_mode && !adev->native_playback_enabled) ||
             (!is_it_true_mode && adev->native_playback_enabled)){
            ret = true;
            ALOGD("napb: time to toggle native mode");
        }
    }

    return ret;
}

int select_devices(struct audio_device *adev, audio_usecase_t uc_id)
{
    snd_device_t out_snd_device = SND_DEVICE_NONE;
@@ -846,6 +936,8 @@ int select_devices(struct audio_device *adev, audio_usecase_t uc_id)
    struct listnode *node;
    int status = 0;

    ALOGD("%s for use case (%s)", __func__, use_case_table[uc_id]);

    usecase = get_usecase_from_list(adev, uc_id);
    if (usecase == NULL) {
        ALOGE("%s: Could not find the usecase(%d)", __func__, uc_id);
@@ -924,6 +1016,8 @@ int select_devices(struct audio_device *adev, audio_usecase_t uc_id)

    if (out_snd_device == usecase->out_snd_device &&
        in_snd_device == usecase->in_snd_device) {

        if (!force_device_switch(usecase))
            return 0;
    }

+3 −0
Original line number Diff line number Diff line
@@ -358,6 +358,7 @@ struct audio_device {
    int perf_lock_handle;
    int perf_lock_opts[MAX_PERF_LOCK_OPTS];
    int perf_lock_opts_size;
    bool native_playback_enabled;
};

int select_devices(struct audio_device *adev,
@@ -377,6 +378,8 @@ struct audio_usecase *get_usecase_from_list(struct audio_device *adev,

bool is_offload_usecase(audio_usecase_t uc_id);

bool audio_is_true_native_stream_active(struct audio_device *adev);

int pcm_ioctl(struct pcm *pcm, int request, ...);

int get_snd_card_state(struct audio_device *adev);
+207 −106

File changed.

Preview size limit exceeded, changes collapsed.

Loading