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

Commit 287348c7 authored by Surendar Karka's avatar Surendar Karka
Browse files

audio: add support to query presentation position from DSP



Add support to query presentation position from DSP
in system time domain.

Change-Id: I475aeedb7a3691027698ca91747b801dff569d21
Signed-off-by: default avatarSurendar Karka <skarka@codeaurora.org>
parent 1aee8389
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -249,6 +249,12 @@ struct audio_device_config_param {
   struct audio_device_cfg_param dev_cfg_params;
};

struct audio_out_presentation_position_param {
    struct timespec timestamp;
    uint64_t frames;
    int32_t clock_id;
};

typedef struct mix_matrix_params {
    uint16_t num_output_channels;
    uint16_t num_input_channels;
@@ -282,6 +288,7 @@ typedef union {
    struct audio_device_cfg_param device_cfg;
    struct mix_matrix_params mm_params;
    struct audio_license_params license_params;
    struct audio_out_presentation_position_param pos_param;
} audio_extn_param_payload;

typedef enum {
@@ -305,6 +312,7 @@ typedef enum {
    AUDIO_EXTN_PARAM_CH_MIX_MATRIX_PARAMS,
    /* License information */
    AUDIO_EXTN_PARAM_LICENSE_PARAMS,
    AUDIO_EXTN_PARAM_OUT_PRESENTATION_POSITION,
} audio_extn_param_id;

typedef union {
+33 −0
Original line number Diff line number Diff line
@@ -3132,6 +3132,13 @@ int audio_extn_out_get_param_data(struct stream_out *out,
                    ALOGE("%s:: avdrift query failed error %d", __func__, ret);
            }
            break;
        case AUDIO_EXTN_PARAM_OUT_PRESENTATION_POSITION:
            ret = audio_ext_get_presentation_position(out,
                      (struct audio_out_presentation_position_param *)payload);
                if (ret < 0)
                    ALOGE("%s:: presentation position query failed error %d",
                           __func__, ret);
            break;
        default:
            ALOGE("%s:: unsupported param_id %d", __func__, param_id);
            break;
@@ -5164,3 +5171,29 @@ void audio_extn_get_parameters(const struct audio_device *adev,
    ALOGD_IF(kv_pairs != NULL, "%s: returns %s", __func__, kv_pairs);
    free(kv_pairs);
}

int audio_ext_get_presentation_position(struct stream_out *out,
                           struct audio_out_presentation_position_param *pos_param)
{
    int ret = -ENODATA;

    if (!out) {
        ALOGE("%s:: Invalid stream",__func__);
        return ret;
    }

    if (is_offload_usecase(out->usecase)) {
        if (out->compr != NULL)
            ret = audio_extn_utils_compress_get_dsp_presentation_pos(out,
                                  &pos_param->frames, &pos_param->timestamp, pos_param->clock_id);
    } else {
        if (out->pcm)
            ret = audio_extn_utils_pcm_get_dsp_presentation_pos(out,
                                  &pos_param->frames, &pos_param->timestamp, pos_param->clock_id);
    }

    ALOGV("%s frames %lld timestamp %lld", __func__, (long long int)pos_param->frames,
           pos_param->timestamp.tv_sec*1000000000LL + pos_param->timestamp.tv_nsec);

    return ret;
}
+6 −0
Original line number Diff line number Diff line
@@ -1083,6 +1083,12 @@ int audio_extn_utils_set_pan_scale_params(
int audio_extn_utils_set_downmix_params(
            struct stream_out *out,
            struct mix_matrix_params *mm_params);
int audio_ext_get_presentation_position(struct stream_out *out,
            struct audio_out_presentation_position_param *pos_param);
int audio_extn_utils_compress_get_dsp_presentation_pos(struct stream_out *out,
            uint64_t *frames, struct timespec *timestamp, int32_t clock_id);
int audio_extn_utils_pcm_get_dsp_presentation_pos(struct stream_out *out,
            uint64_t *frames, struct timespec *timestamp, int32_t clock_id);
#ifdef AUDIO_HW_LOOPBACK_ENABLED
/* API to create audio patch */
int audio_extn_hw_loopback_create_audio_patch(struct audio_hw_device *dev,
+76 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@
#include <log/log.h>
#include <cutils/misc.h>
#include <unistd.h>
#include <sys/ioctl.h>


#include "audio_hw.h"
@@ -39,6 +40,7 @@
#include "voice.h"
#include <sound/compress_params.h>
#include <sound/compress_offload.h>
#include <sound/devdep_params.h>
#include <tinycompress/tinycompress.h>

#ifdef DYNAMIC_LOG_ENABLED
@@ -2258,6 +2260,80 @@ int audio_extn_utils_compress_set_start_delay(
}
#endif

#ifdef SNDRV_COMPRESS_DSP_POSITION
int audio_extn_utils_compress_get_dsp_presentation_pos(struct stream_out *out,
            uint64_t *frames, struct timespec *timestamp, int32_t clock_id)
{
    int ret = -EINVAL;
    uint64_t *val = NULL;
    uint64_t time = 0;
    struct snd_compr_metadata metadata;

    ALOGV("%s:: Quering DSP position with clock id %d",__func__, clock_id);
    metadata.key = SNDRV_COMPRESS_DSP_POSITION;
    metadata.value[0] = clock_id;
    ret = compress_get_metadata(out->compr, &metadata);
    if (ret) {
        ALOGE("%s::error %s", __func__, compress_get_error(out->compr));
        ret = -errno;
        goto exit;
    }
    val = (uint64_t *)&metadata.value[1];
    *frames = *val;
    time = *(val + 1);
    timestamp->tv_sec = time / 1000000;
    timestamp->tv_nsec = (time % 1000000)*1000;

exit:
    return ret;
}
#else
int audio_extn_utils_compress_get_dsp_presentation_pos(struct stream_out *out __unused,
            uint64_t *frames __unused, struct timespec *timestamp __unused,
            int32_t clock_id __unused)
{
    ALOGD("%s:: dsp presentation position not supported", __func__);
    return 0;

}
#endif

#ifdef SNDRV_PCM_IOCTL_DSP_POSITION
int audio_extn_utils_pcm_get_dsp_presentation_pos(struct stream_out *out,
            uint64_t *frames, struct timespec *timestamp, int32_t clock_id)
{
    int ret = -EINVAL;
    uint64_t time = 0;
    struct snd_pcm_prsnt_position prsnt_position;

    ALOGV("%s:: Quering DSP position with clock id %d",__func__, clock_id);
    prsnt_position.clock_id = clock_id;
    ret = pcm_ioctl(out->pcm, SNDRV_PCM_IOCTL_DSP_POSITION, &prsnt_position);
    if (ret) {
        ALOGE("%s::error  %d", __func__, ret);
        ret = -EIO;
        goto exit;
    }

    *frames = prsnt_position.frames;
    time = prsnt_position.timestamp;
    timestamp->tv_sec = time / 1000000;
    timestamp->tv_nsec = (time % 1000000)*1000;

exit:
    return ret;
}
#else
int audio_extn_utils_pcm_get_dsp_presentation_pos(struct stream_out *out __unused,
            uint64_t *frames __unused, struct timespec *timestamp __unused,
            int32_t clock_id __unused)
{
    ALOGD("%s:: dsp presentation position not supported", __func__);
    return 0;

}
#endif

#define MAX_SND_CARD 8
#define RETRY_US 1000000
#define RETRY_NUMBER 40
+9 −1
Original line number Diff line number Diff line
/*
 * Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
 * Copyright (c) 2016-2019, The Linux Foundation. All rights reserved.
 * Not a Contribution.
 *
 * Copyright (C) 2011 The Android Open Source Project *
@@ -332,6 +332,12 @@ struct qahw_out_correct_drift {
    int64_t        adjust_time;
};

struct qahw_out_presentation_position_param {
    struct timespec timestamp;
    uint64_t frames;
    int32_t clock_id;
};

#define QAHW_MAX_ADSP_STREAM_CMD_PAYLOAD_LEN 512

typedef enum {
@@ -396,6 +402,7 @@ typedef union {
    struct qahw_device_cfg_param device_cfg_params;
    struct qahw_mix_matrix_params mix_matrix_params;
    struct qahw_license_params license_params;
    struct qahw_out_presentation_position_param pos_param;
} qahw_param_payload;

typedef enum {
@@ -415,6 +422,7 @@ typedef enum {
    QAHW_PARAM_OUT_MIX_MATRIX_PARAMS,
    QAHW_PARAM_CH_MIX_MATRIX_PARAMS,
    QAHW_PARAM_LICENSE_PARAMS,
    QAHW_PARAM_OUT_PRESENTATION_POSITION,
} qahw_param_id;

typedef union {
Loading