Re: [PATCH v2 8/9] ASoC: qdsp6-dai: add gapless support

From: Srinivas Kandagatla
Date: Wed Jul 22 2020 - 05:00:11 EST


Thanks Pierre for quick review!

On 21/07/2020 20:53, Pierre-Louis Bossart wrote:




ÂÂÂÂÂ case ASM_CLIENT_EVENT_CMD_EOS_DONE:
-ÂÂÂÂÂÂÂ prtd->state = Q6ASM_STREAM_STOPPED;
+ÂÂÂÂÂÂÂ spin_lock_irqsave(&prtd->lock, flags);
+ÂÂÂÂÂÂÂ if (prtd->notify_on_drain) {
+ÂÂÂÂÂÂÂÂÂÂÂ if (substream->partial_drain) {
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ /**

why the kernel-doc style comment?

Nothing intentional, will fix this!

[...]


-static int q6asm_dai_compr_set_params(struct snd_soc_component *component,
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ struct snd_compr_stream *stream,
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ struct snd_compr_params *params)
+static int __q6asm_dai_compr_set_codec_params(struct snd_soc_component *component,
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ struct snd_compr_stream *stream,
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ struct snd_codec *codec,
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ int stream_id)

not sure I get why you added the __ prefix, does it have any semantic meaning?
Nope, just to mark them it as internal function, as the function name is very much similar to q6asm_dai_compr_set_params() callback!
I will try to come up with better naming and also move the indirection changes to a separate patch!


 {
ÂÂÂÂÂ struct snd_compr_runtime *runtime = stream->runtime;
ÂÂÂÂÂ struct q6asm_dai_rtd *prtd = runtime->private_data;
-ÂÂÂ struct snd_soc_pcm_runtime *rtd = stream->private_data;
-ÂÂÂ int dir = stream->direction;
-ÂÂÂ struct q6asm_dai_data *pdata;
ÂÂÂÂÂ struct q6asm_flac_cfg flac_cfg;
ÂÂÂÂÂ struct q6asm_wma_cfg wma_cfg;
ÂÂÂÂÂ struct q6asm_alac_cfg alac_cfg;
@@ -667,53 +718,18 @@ static int q6asm_dai_compr_set_params(struct snd_soc_component *component,
ÂÂÂÂÂ struct snd_dec_alac *alac;
ÂÂÂÂÂ struct snd_dec_ape *ape;
-ÂÂÂ codec_options = &(prtd->codec_param.codec.options);
-
-
-ÂÂÂ memcpy(&prtd->codec_param, params, sizeof(*params));
-
-ÂÂÂ pdata = snd_soc_component_get_drvdata(component);
-ÂÂÂ if (!pdata)
-ÂÂÂÂÂÂÂ return -EINVAL;
-
-ÂÂÂ if (!prtd || !prtd->audio_client) {
-ÂÂÂÂÂÂÂ dev_err(dev, "private data null or audio client freed\n");
-ÂÂÂÂÂÂÂ return -EINVAL;
-ÂÂÂ }
-
-ÂÂÂ prtd->periods = runtime->fragments;
-ÂÂÂ prtd->pcm_count = runtime->fragment_size;
-ÂÂÂ prtd->pcm_size = runtime->fragments * runtime->fragment_size;
-ÂÂÂ prtd->bits_per_sample = 16;
-ÂÂÂ if (dir == SND_COMPRESS_PLAYBACK) {
-ÂÂÂÂÂÂÂ ret = q6asm_open_write(prtd->audio_client, prtd->stream_id,
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ params->codec.id, params->codec.profile,
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ prtd->bits_per_sample, true);
-
-ÂÂÂÂÂÂÂ if (ret < 0) {
-ÂÂÂÂÂÂÂÂÂÂÂ dev_err(dev, "q6asm_open_write failed\n");
-ÂÂÂÂÂÂÂÂÂÂÂ q6asm_audio_client_free(prtd->audio_client);
-ÂÂÂÂÂÂÂÂÂÂÂ prtd->audio_client = NULL;
-ÂÂÂÂÂÂÂÂÂÂÂ return ret;
-ÂÂÂÂÂÂÂ }
-ÂÂÂ }
+ÂÂÂ codec_options = &(prtd->codec.options);
-ÂÂÂ prtd->session_id = q6asm_get_session_id(prtd->audio_client);
-ÂÂÂ ret = q6routing_stream_open(rtd->dai_link->id, LEGACY_PCM_MODE,
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ prtd->session_id, dir);
-ÂÂÂ if (ret) {
-ÂÂÂÂÂÂÂ dev_err(dev, "Stream reg failed ret:%d\n", ret);
-ÂÂÂÂÂÂÂ return ret;
-ÂÂÂ }
+ÂÂÂ memcpy(&prtd->codec, codec, sizeof(*codec));
-ÂÂÂ switch (params->codec.id) {
+ÂÂÂ switch (codec->id) {
ÂÂÂÂÂ case SND_AUDIOCODEC_FLAC:
ÂÂÂÂÂÂÂÂÂ memset(&flac_cfg, 0x0, sizeof(struct q6asm_flac_cfg));
ÂÂÂÂÂÂÂÂÂ flac = &codec_options->flac_d;
-ÂÂÂÂÂÂÂ flac_cfg.ch_cfg = params->codec.ch_in;
-ÂÂÂÂÂÂÂ flac_cfg.sample_rate =Â params->codec.sample_rate;

all these indirection changes could have gone in a earlier patch, this adds a lot of changes that make this patch long to review. Same comment for all formats

+ÂÂÂÂÂÂÂ flac_cfg.ch_cfg = codec->ch_in;
+ÂÂÂÂÂÂÂ flac_cfg.sample_rate = codec->sample_rate;
ÂÂÂÂÂÂÂÂÂ flac_cfg.stream_info_present = 1;
ÂÂÂÂÂÂÂÂÂ flac_cfg.sample_size = flac->sample_size;
ÂÂÂÂÂÂÂÂÂ flac_cfg.min_blk_size = flac->min_blk_size;

[...]

...

@@ -917,6 +1018,14 @@ static int q6asm_dai_compr_trigger(struct snd_soc_component *component,
ÂÂÂÂÂÂÂÂÂ ret = q6asm_cmd_nowait(prtd->audio_client, prtd->stream_id,
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ CMD_PAUSE);
ÂÂÂÂÂÂÂÂÂ break;
+ÂÂÂ case SND_COMPR_TRIGGER_NEXT_TRACK:
+ÂÂÂÂÂÂÂ prtd->next_track = true;
+ÂÂÂÂÂÂÂ prtd->next_track_stream_id = (prtd->stream_id == 1 ? 2 : 1);

it's rather odd, the initialization above uses next_track_stream_id = 0?

Vaild stream ids start from 1, So we are toggling this between 1 and 2.
So when we set next_track_stream_id to 0, that means we have opened the new next stream id and is set to prtd->stream_id. This logic is to ensure that we are not going to open next stream id twice!


+ÂÂÂÂÂÂÂ break;
+ÂÂÂ case SND_COMPR_TRIGGER_DRAIN:
+ÂÂÂ case SND_COMPR_TRIGGER_PARTIAL_DRAIN:
+ÂÂÂÂÂÂÂ prtd->notify_on_drain = true;
+ÂÂÂÂÂÂÂ break;
ÂÂÂÂÂ default:
ÂÂÂÂÂÂÂÂÂ ret = -EINVAL;
ÂÂÂÂÂÂÂÂÂ break;
diff --git a/sound/soc/qcom/qdsp6/q6asm.h b/sound/soc/qcom/qdsp6/q6asm.h
index 69513ac1fa55..a8dddfeb28da 100644
--- a/sound/soc/qcom/qdsp6/q6asm.h
+++ b/sound/soc/qcom/qdsp6/q6asm.h
@@ -34,6 +34,7 @@ enum {
 #define MAX_SESSIONS 8
 #define NO_TIMESTAMP 0xFF00
 #define FORMAT_LINEAR_PCM 0x0000
+#define ASM_LAST_BUFFER_FLAGÂÂÂÂÂÂÂÂÂÂ BIT(30)
 struct q6asm_flac_cfg {
ÂÂÂÂÂÂÂÂÂ u32 sample_rate;