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

Commit f8b50aa7 authored by Eric Laurent's avatar Eric Laurent
Browse files

resolve merge conflicts of 8d89f409 to nyc-mr1-dev

Change-Id: I7d832f735432356a078a15cd678e2e11d48fd0b2
parents aeaf9e13 8d89f409
Loading
Loading
Loading
Loading
+40 −11
Original line number Original line Diff line number Diff line
@@ -636,6 +636,8 @@ static void check_and_route_capture_usecases(struct audio_device *adev,
    bool switch_device[AUDIO_USECASE_MAX];
    bool switch_device[AUDIO_USECASE_MAX];
    int i, num_uc_to_switch = 0;
    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
     * This function is to make sure that all the active capture usecases
     * are always routed to the same input sound device.
     * are always routed to the same input sound device.
@@ -1456,7 +1458,7 @@ static int check_input_parameters(uint32_t sample_rate,
                                  audio_format_t format,
                                  audio_format_t format,
                                  int channel_count)
                                  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);
        ALOGE("%s: unsupported AUDIO FORMAT (%d) ", __func__, format);
        return -EINVAL;
        return -EINVAL;
    }
    }
@@ -1499,9 +1501,8 @@ static size_t get_input_buffer_size(uint32_t sample_rate,
    size = (sample_rate * AUDIO_CAPTURE_PERIOD_DURATION_MSEC) / 1000;
    size = (sample_rate * AUDIO_CAPTURE_PERIOD_DURATION_MSEC) / 1000;
    if (is_low_latency)
    if (is_low_latency)
        size = configured_low_latency_capture_period_size;
        size = configured_low_latency_capture_period_size;
    /* ToDo: should use frame_size computed based on the format and

       channel_count here. */
    size *= channel_count * audio_bytes_per_sample(format);
    size *= sizeof(short) * channel_count;


    /* make sure the size is multiple of 32 bytes
    /* make sure the size is multiple of 32 bytes
     * At 48 kHz mono 16-bit PCM:
     * At 48 kHz mono 16-bit PCM:
@@ -2121,9 +2122,10 @@ static uint32_t in_get_channels(const struct audio_stream *stream)
    return in->channel_mask;
    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)
static int in_set_format(struct audio_stream *stream __unused, audio_format_t format __unused)
@@ -2237,6 +2239,7 @@ static ssize_t in_read(struct audio_stream_in *stream, void *buffer,
    struct stream_in *in = (struct stream_in *)stream;
    struct stream_in *in = (struct stream_in *)stream;
    struct audio_device *adev = in->dev;
    struct audio_device *adev = in->dev;
    int i, ret = -1;
    int i, ret = -1;
    int *int_buf_stream = NULL;


    lock_input_stream(in);
    lock_input_stream(in);


@@ -2267,13 +2270,26 @@ static ssize_t in_read(struct audio_stream_in *stream, void *buffer,
    if (in->pcm) {
    if (in->pcm) {
        if (use_mmap) {
        if (use_mmap) {
            ret = pcm_mmap_read(in->pcm, buffer, bytes);
            ret = pcm_mmap_read(in->pcm, buffer, bytes);
        } else
        } else {
            ret = pcm_read(in->pcm, buffer, bytes);
            ret = pcm_read(in->pcm, buffer, bytes);

        }
        if (ret < 0) {
        if (ret < 0) {
            ALOGE("Failed to read w/err %s", strerror(errno));
            ALOGE("Failed to read w/err %s", strerror(errno));
            ret = -errno;
            ret = -errno;
        }
        }
        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;
            }
        }
    }
    }


    release_in_focus(in, ns);
    release_in_focus(in, ns);
@@ -2879,8 +2895,19 @@ static int adev_open_input_stream(struct audio_hw_device *dev,
    in->channel_mask = config->channel_mask;
    in->channel_mask = config->channel_mask;
    in->capture_handle = handle;
    in->capture_handle = handle;
    in->flags = flags;
    in->flags = flags;
    in->format = config->format;
    // in->frames_read = 0;
    // 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 */
    /* Update config params with the requested sample rate and channels */
    if (in->device == AUDIO_DEVICE_IN_TELEPHONY_RX) {
    if (in->device == AUDIO_DEVICE_IN_TELEPHONY_RX) {
        if (config->sample_rate == 0)
        if (config->sample_rate == 0)
@@ -2891,8 +2918,7 @@ static int adev_open_input_stream(struct audio_hw_device *dev,
            ret = -EINVAL;
            ret = -EINVAL;
            goto err_open;
            goto err_open;
        }
        }
        if (config->format == AUDIO_FORMAT_DEFAULT)

            config->format = AUDIO_FORMAT_PCM_16_BIT;
        if (config->format != AUDIO_FORMAT_PCM_16_BIT) {
        if (config->format != AUDIO_FORMAT_PCM_16_BIT) {
            config->format = AUDIO_FORMAT_PCM_16_BIT;
            config->format = AUDIO_FORMAT_PCM_16_BIT;
            ret = -EINVAL;
            ret = -EINVAL;
@@ -2915,6 +2941,9 @@ static int adev_open_input_stream(struct audio_hw_device *dev,
        in->config = in->realtime ? pcm_config_audio_capture_rt :
        in->config = in->realtime ? pcm_config_audio_capture_rt :
                                  pcm_config_audio_capture;
                                  pcm_config_audio_capture;


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

        if (!in->realtime) {
        if (!in->realtime) {
            frame_size = audio_stream_in_frame_size(&in->stream);
            frame_size = audio_stream_in_frame_size(&in->stream);
            buffer_size = get_input_buffer_size(config->sample_rate,
            buffer_size = get_input_buffer_size(config->sample_rate,
+1 −0
Original line number Original line Diff line number Diff line
@@ -207,6 +207,7 @@ struct stream_in {
    int af_period_multiplier;
    int af_period_multiplier;
    bool routing_change;
    bool routing_change;
    struct audio_device *dev;
    struct audio_device *dev;
    audio_format_t format;
};
};


typedef enum {
typedef enum {
+6 −0
Original line number Original line Diff line number Diff line
@@ -1096,3 +1096,9 @@ int platform_get_snd_device_name_extn(void *platform __unused,
    return 0;
    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 Original line 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_VOICE_REC_HEADSET_MIC] = "headset-mic",


    [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-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_UNPROCESSED_HEADSET_MIC] = "headset-mic",


    [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
    [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_MIC] = ACDB_ID_VOICE_REC_MIC,
    [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
    [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,
    [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_MIC)},
    {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_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_THREE_MIC)},
    {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
    {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
@@ -2105,7 +2114,19 @@ snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_d
        }
        }
    } else if (source == AUDIO_SOURCE_UNPROCESSED) {
    } else if (source == AUDIO_SOURCE_UNPROCESSED) {
        if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
        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;
                snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
            }
        } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
        } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
            snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
            snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
        }
        }
@@ -2532,6 +2553,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,
int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
                                    const char * hw_interface)
                                    const char * hw_interface)
{
{
+3 −0
Original line number Original line Diff line number Diff line
@@ -135,6 +135,9 @@ enum {


    SND_DEVICE_IN_UNPROCESSED_MIC,
    SND_DEVICE_IN_UNPROCESSED_MIC,
    SND_DEVICE_IN_UNPROCESSED_HEADSET_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,
    SND_DEVICE_IN_VOICE_RX,


Loading