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

Commit 4ed66e62 authored by vivek mehta's avatar vivek mehta Committed by Eric Laurent
Browse files

hal: enable 24 bit capture

- capture 24_8 bit data from driver
- convert data to 8_24 bit and pass above
- allow 24 bit capture only when voice call is not active

Bug: git 27348418

Change-Id: I19138f008275ba2aa36f44c1b0aecbe6547bd399
parent 1015d94f
Loading
Loading
Loading
Loading
+39 −9
Original line number Diff line number Diff line
@@ -485,6 +485,8 @@ static void check_and_route_capture_usecases(struct audio_device *adev,
    bool switch_device[AUDIO_USECASE_MAX];
    int i, num_uc_to_switch = 0;

    platform_check_and_set_capture_backend_cfg(adev, uc_info, snd_device);

    /*
     * This function is to make sure that all the active capture usecases
     * are always routed to the same input sound device.
@@ -1292,7 +1294,7 @@ static int check_input_parameters(uint32_t sample_rate,
                                  audio_format_t format,
                                  int channel_count)
{
    if (format != AUDIO_FORMAT_PCM_16_BIT) {
    if ((format != AUDIO_FORMAT_PCM_16_BIT) && (format != AUDIO_FORMAT_PCM_8_24_BIT)) {
        ALOGE("%s: unsupported AUDIO FORMAT (%d) ", __func__, format);
        return -EINVAL;
    }
@@ -1335,9 +1337,8 @@ static size_t get_input_buffer_size(uint32_t sample_rate,
    size = (sample_rate * AUDIO_CAPTURE_PERIOD_DURATION_MSEC) / 1000;
    if (is_low_latency)
        size = configured_low_latency_capture_period_size;
    /* ToDo: should use frame_size computed based on the format and
       channel_count here. */
    size *= sizeof(short) * channel_count;

    size *= channel_count * audio_bytes_per_sample(format);

    /* make sure the size is multiple of 32 bytes
     * At 48 kHz mono 16-bit PCM:
@@ -1942,9 +1943,10 @@ static uint32_t in_get_channels(const struct audio_stream *stream)
    return in->channel_mask;
}

static audio_format_t in_get_format(const struct audio_stream *stream __unused)
static audio_format_t in_get_format(const struct audio_stream *stream)
{
    return AUDIO_FORMAT_PCM_16_BIT;
    struct stream_in *in = (struct stream_in *)stream;
    return in->format;
}

static int in_set_format(struct audio_stream *stream __unused, audio_format_t format __unused)
@@ -2055,6 +2057,7 @@ static ssize_t in_read(struct audio_stream_in *stream, void *buffer,
    struct stream_in *in = (struct stream_in *)stream;
    struct audio_device *adev = in->dev;
    int i, ret = -1;
    int *int_buf_stream = NULL;

    lock_input_stream(in);

@@ -2084,8 +2087,22 @@ static ssize_t in_read(struct audio_stream_in *stream, void *buffer,
    if (in->pcm) {
        if (in->usecase == USECASE_AUDIO_RECORD_AFE_PROXY) {
            ret = pcm_mmap_read(in->pcm, buffer, bytes);
        } else
        } else {
            ret = pcm_read(in->pcm, buffer, bytes);
            if (!ret && bytes > 0 && (in->format == AUDIO_FORMAT_PCM_8_24_BIT)) {
                if (bytes % 4 == 0) {
                    /* data from DSP comes in 24_8 format, convert it to 8_24 */
                    int_buf_stream = buffer;
                    for (size_t itt=0; itt < bytes/4 ; itt++) {
                        int_buf_stream[itt] >>= 8;
                    }
                } else {
                    ALOGE("%s: !!! something wrong !!! ... data not 32 bit aligned ", __func__);
                    ret = -EINVAL;
                    goto exit;
                }
            }
        }
    }

    if (adev->adm_abandon_focus)
@@ -2689,8 +2706,19 @@ static int adev_open_input_stream(struct audio_hw_device *dev,
    in->channel_mask = config->channel_mask;
    in->capture_handle = handle;
    in->flags = flags;
    in->format = config->format;
    // in->frames_read = 0;

    if (in->format == AUDIO_FORMAT_DEFAULT)
        config->format = AUDIO_FORMAT_PCM_16_BIT;

    if (config->format == AUDIO_FORMAT_PCM_FLOAT ||
        config->format == AUDIO_FORMAT_PCM_24_BIT_PACKED) {
        config->format = AUDIO_FORMAT_PCM_8_24_BIT;
        ret = -EINVAL;
        goto err_open;
    }

    /* Update config params with the requested sample rate and channels */
    if (in->device == AUDIO_DEVICE_IN_TELEPHONY_RX) {
        if (config->sample_rate == 0)
@@ -2701,8 +2729,7 @@ static int adev_open_input_stream(struct audio_hw_device *dev,
            ret = -EINVAL;
            goto err_open;
        }
        if (config->format == AUDIO_FORMAT_DEFAULT)
            config->format = AUDIO_FORMAT_PCM_16_BIT;

        if (config->format != AUDIO_FORMAT_PCM_16_BIT) {
            config->format = AUDIO_FORMAT_PCM_16_BIT;
            ret = -EINVAL;
@@ -2722,6 +2749,9 @@ static int adev_open_input_stream(struct audio_hw_device *dev,
        }
        in->config = pcm_config_audio_capture;

        if (config->format == AUDIO_FORMAT_PCM_8_24_BIT)
            in->config.format = PCM_FORMAT_S24_LE;

        frame_size = audio_stream_in_frame_size(&in->stream);
        buffer_size = get_input_buffer_size(config->sample_rate,
                                            config->format,
+1 −0
Original line number Diff line number Diff line
@@ -203,6 +203,7 @@ struct stream_in {
    bool is_st_session_active;

    struct audio_device *dev;
    audio_format_t format;
};

typedef enum {
+6 −0
Original line number Diff line number Diff line
@@ -1096,3 +1096,9 @@ int platform_get_snd_device_name_extn(void *platform __unused,
    return 0;
}

bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev __unused,
                                              struct audio_usecase *usecase __unused)
{
    return false;
}
+42 −1
Original line number Diff line number Diff line
@@ -264,6 +264,9 @@ static const char * const device_table[SND_DEVICE_MAX] = {
    [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",

    [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
    [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = "voice-rec-dmic-ef",
    [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = "three-mic",
    [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = "quad-mic",
    [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "headset-mic",

    [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
@@ -357,6 +360,9 @@ static int acdb_device_table[SND_DEVICE_MAX] = {

    [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC,
    [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
    [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = 35,
    [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = 125,
    [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = 125,

    [SND_DEVICE_IN_VOICE_RX] = 44,

@@ -456,6 +462,9 @@ static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {

    {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
    {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
    {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_STEREO_MIC)},
    {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_THREE_MIC)},
    {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_QUAD_MIC)},

    {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
    {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
@@ -2104,7 +2113,19 @@ snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_d
        }
    } else if (source == AUDIO_SOURCE_UNPROCESSED) {
        if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
            if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
                 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
                       (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
                snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
            } else if (((int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
                       (my_data->source_mic_type & SOURCE_THREE_MIC)) {
                snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
            } else if (((int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
                       (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
                snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
            } else {
                snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
            }
        } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
            snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
        }
@@ -2529,6 +2550,26 @@ int64_t platform_render_latency(audio_usecase_t usecase)
    }
}

bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
         struct audio_usecase *usecase, snd_device_t snd_device)
{
    enum pcm_format  in_pcm_format = PCM_FORMAT_S16_LE;

    if (adev && adev->active_input)
        in_pcm_format = adev->active_input->config.format;

    // allow 24 bit recording only if voice call is not active
    if (!voice_is_in_call(adev) &&
        adev->mode != AUDIO_MODE_IN_COMMUNICATION &&
        in_pcm_format == PCM_FORMAT_S24_LE) {
        audio_route_apply_and_update_path(adev->audio_route, "set-capture-format-24le");
    } else {
        audio_route_apply_and_update_path(adev->audio_route, "set-capture-format-default");
    }

    return true;
}

int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
                                    const char * hw_interface)
{
+3 −0
Original line number Diff line number Diff line
@@ -135,6 +135,9 @@ enum {

    SND_DEVICE_IN_UNPROCESSED_MIC,
    SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC,
    SND_DEVICE_IN_UNPROCESSED_STEREO_MIC,
    SND_DEVICE_IN_UNPROCESSED_THREE_MIC,
    SND_DEVICE_IN_UNPROCESSED_QUAD_MIC,

    SND_DEVICE_IN_VOICE_RX,

Loading