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

Commit 65358ab2 authored by Deeraj Soman's avatar Deeraj Soman Committed by Gerrit - the friendly Code Review server
Browse files

hal: Add support for buffer duration in offload usecase

Add support for buffer duration in offload usecase.
HAL configures the buffer size corresponding to the
duration specified by the client.

Change-Id: I73faf8ddd633ba8a889f3189fcc6d4392a0e1a42
parent 14230921
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -1525,11 +1525,15 @@ uint32_t hal_format_to_pcm(audio_format_t hal_format)

uint32_t get_alsa_fragment_size(uint32_t bytes_per_sample,
                                  uint32_t sample_rate,
                                  uint32_t noOfChannels)
                                  uint32_t noOfChannels,
                                  int64_t duration_ms)
{
    uint32_t fragment_size = 0;
    uint32_t pcm_offload_time = PCM_OFFLOAD_BUFFER_DURATION;

    if (duration_ms >= MIN_OFFLOAD_BUFFER_DURATION_MS && duration_ms <= MAX_OFFLOAD_BUFFER_DURATION_MS)
        pcm_offload_time = duration_ms;

    fragment_size = (pcm_offload_time
                     * sample_rate
                     * bytes_per_sample
@@ -1564,7 +1568,8 @@ void audio_extn_utils_update_direct_pcm_fragment_size(struct stream_out *out)
    out->compr_config.fragment_size =
             get_alsa_fragment_size(hal_op_bytes_per_sample,
                                      out->sample_rate,
                                      popcount(out->channel_mask));
                                      popcount(out->channel_mask),
                                      out->info.duration_us / 1000);

    if ((src_format != dst_format) &&
         hal_op_bytes_per_sample != hal_ip_bytes_per_sample) {
+4 −0
Original line number Diff line number Diff line
@@ -7463,6 +7463,10 @@ int adev_open_output_stream(struct audio_hw_device *dev,

            out->compr_config.fragments = DIRECT_PCM_NUM_FRAGMENTS;

            if ((config->offload_info.duration_us >= MIN_OFFLOAD_BUFFER_DURATION_MS * 1000) &&
                   (config->offload_info.duration_us <= MAX_OFFLOAD_BUFFER_DURATION_MS * 1000))
                out->info.duration_us = (int64_t)config->offload_info.duration_us;

            /* Check if alsa session is configured with the same format as HAL input format,
             * if not then derive correct fragment size needed to accomodate the
             * conversion of HAL input format to alsa format.
+14 −0
Original line number Diff line number Diff line
@@ -7948,6 +7948,9 @@ uint32_t platform_get_compress_offload_buffer_size(audio_offload_info_t* info)
{
    char value[PROPERTY_VALUE_MAX] = {0};
    uint32_t fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE;
    uint32_t new_fragment_size = 0;
    int32_t duration_ms = 0;
    int channel_count = 0;
    if((property_get("vendor.audio.offload.buffer.size.kb", value, "")) &&
            atoi(value)) {
        fragment_size =  atoi(value) * 1024;
@@ -7961,6 +7964,17 @@ uint32_t platform_get_compress_offload_buffer_size(audio_offload_info_t* info)
        fragment_size = info->offload_buffer_size;
    }

    /* Use client specified buffer size if mentioned */
    if ((info != NULL) && (info->duration_us > 0)) {
        duration_ms = info->duration_us / 1000;
        channel_count = audio_channel_count_from_in_mask(info->channel_mask);

        new_fragment_size = (duration_ms * info->sample_rate * channel_count * audio_bytes_per_sample(info->format)) / 1000;
        ALOGI("%s:: Overwriting offload buffer size with client requested size old:%d new:%d", __func__, fragment_size, new_fragment_size);

        fragment_size = new_fragment_size;
    }

    if (info != NULL) {
        if (info->is_streaming && info->has_video) {
            fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING;