From 540284901837726119cd0a1f672787587fffae80 Mon Sep 17 00:00:00 2001 From: Preetam Singh Ranawat Date: Mon, 4 Sep 2017 11:42:26 +0530 Subject: [PATCH] dsp: add CELT encoder support Add CELT encoder support to enable audio broadcast over split a2dp. Change-Id: If0d927913c5e525ff1cebf857323ab70be2122a1 Signed-off-by: Preetam Singh Ranawat --- asoc/msm-dai-q6-v2.c | 15 +++++++++-- dsp/q6afe.c | 3 ++- include/dsp/apr_audio-v2.h | 51 ++++++++++++++++++++++++++++++++++++-- 3 files changed, 64 insertions(+), 5 deletions(-) diff --git a/asoc/msm-dai-q6-v2.c b/asoc/msm-dai-q6-v2.c index 6b620a5c8e..25eb2ecff3 100644 --- a/asoc/msm-dai-q6-v2.c +++ b/asoc/msm-dai-q6-v2.c @@ -49,6 +49,7 @@ enum { ENC_FMT_AAC_V2 = ASM_MEDIA_FMT_AAC_V2, ENC_FMT_APTX = ASM_MEDIA_FMT_APTX, ENC_FMT_APTX_HD = ASM_MEDIA_FMT_APTX_HD, + ENC_FMT_CELT = ASM_MEDIA_FMT_CELT, }; enum { @@ -2146,7 +2147,12 @@ static int msm_dai_q6_afe_enc_cfg_get(struct snd_kcontrol *kcontrol, case ENC_FMT_APTX_HD: memcpy(ucontrol->value.bytes.data + format_size, &dai_data->enc_config.data, - sizeof(struct asm_aac_enc_cfg_v2_t)); + sizeof(struct asm_custom_enc_cfg_t)); + break; + case ENC_FMT_CELT: + memcpy(ucontrol->value.bytes.data + format_size, + &dai_data->enc_config.data, + sizeof(struct asm_celt_enc_cfg_t)); break; default: pr_debug("%s: unknown format = %d\n", @@ -2190,7 +2196,12 @@ static int msm_dai_q6_afe_enc_cfg_put(struct snd_kcontrol *kcontrol, case ENC_FMT_APTX_HD: memcpy(&dai_data->enc_config.data, ucontrol->value.bytes.data + format_size, - sizeof(struct asm_custom_enc_cfg_aptx_t)); + sizeof(struct asm_custom_enc_cfg_t)); + break; + case ENC_FMT_CELT: + memcpy(&dai_data->enc_config.data, + ucontrol->value.bytes.data + format_size, + sizeof(struct asm_celt_enc_cfg_t)); break; default: pr_debug("%s: Ignore enc config for unknown format = %d\n", diff --git a/dsp/q6afe.c b/dsp/q6afe.c index 78be555eb8..a6041b3775 100644 --- a/dsp/q6afe.c +++ b/dsp/q6afe.c @@ -2824,7 +2824,8 @@ static int q6afe_send_enc_config(u16 port_id, pr_debug("%s:update DSP for enc format = %d\n", __func__, format); if (format != ASM_MEDIA_FMT_SBC && format != ASM_MEDIA_FMT_AAC_V2 && - format != ASM_MEDIA_FMT_APTX && format != ASM_MEDIA_FMT_APTX_HD) { + format != ASM_MEDIA_FMT_APTX && format != ASM_MEDIA_FMT_APTX_HD && + format != ASM_MEDIA_FMT_CELT) { pr_err("%s:Unsuppported format Ignore AFE config\n", __func__); return 0; } diff --git a/include/dsp/apr_audio-v2.h b/include/dsp/apr_audio-v2.h index 2256b7b4d9..3d9a56cdfe 100644 --- a/include/dsp/apr_audio-v2.h +++ b/include/dsp/apr_audio-v2.h @@ -3252,7 +3252,7 @@ struct asm_aac_enc_cfg_v2_t { #define PCM_CHANNEL_R 2 #define PCM_CHANNEL_C 3 -struct asm_custom_enc_cfg_aptx_t { +struct asm_custom_enc_cfg_t { uint32_t sample_rate; /* Mono or stereo */ uint16_t num_channels; @@ -3263,6 +3263,52 @@ struct asm_custom_enc_cfg_aptx_t { uint8_t channel_mapping[8]; uint32_t custom_size; } __packed; +#define ASM_MEDIA_FMT_CELT 0x00013221 +struct asm_celt_specific_enc_cfg_t { + /* + * Bit rate used for encoding. + * This is used to calculate the upper threshold + * for bytes per frame if vbr_flag is 1. + * Or else, this will be used as a regular constant + * bit rate for encoder output. + * @Range : 32000 to 1536000 + * @Default: 128 + */ + uint32_t bit_rate; + /* + * Frame size used for encoding. + * @Range : 64, 128, 256, 512 + * @Default: 256 + */ + uint16_t frame_size; + /* + * complexity of algorithm. + * @Range : 0-10 + * @Default: 3 + */ + uint16_t complexity; + /* + * Switch variable for prediction feature. + * Used to choose between the level of interframe + * predictions allowed while encoding. + * @Range: + * 0: Independent Frames. + * 1: Short Term interframe prediction allowed. + * 2: Long term prediction allowed. + * @Default: 2 + */ + uint16_t prediction_mode; + /* + * Variable Bit Rate flag. + * @Default: 0 + */ + uint16_t vbr_flag; +} __packed; + +struct asm_celt_enc_cfg_t { + struct asm_custom_enc_cfg_t custom_config; + struct asm_celt_specific_enc_cfg_t celt_specific_config; +} __packed; struct afe_enc_fmt_id_param_t { /* @@ -3331,7 +3377,8 @@ struct afe_port_media_type_t { union afe_enc_config_data { struct asm_sbc_enc_cfg_t sbc_config; struct asm_aac_enc_cfg_v2_t aac_config; - struct asm_custom_enc_cfg_aptx_t aptx_config; + struct asm_custom_enc_cfg_t custom_config; + struct asm_celt_enc_cfg_t celt_config; }; struct afe_enc_config {