ASoC: SOF: compress: Add support for computing timestamps
authorLaurentiu Mihalcea <laurentiu.mihalcea@nxp.com>
Wed, 17 Aug 2022 08:05:29 +0000 (11:05 +0300)
committerMark Brown <broonie@kernel.org>
Wed, 17 Aug 2022 12:00:24 +0000 (13:00 +0100)
We compute the number of pcm_io_frames by dividing the
dai position to size of a frame (channels * sample size).

Reviewed-by: Paul Olaru <paul.olaru@oss.nxp.com>
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: Laurentiu Mihalcea <laurentiu.mihalcea@nxp.com>
Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
Link: https://lore.kernel.org/r/20220817080529.10864-5-daniel.baluta@oss.nxp.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/sof/compress.c

index ac79b46ce3b98f13ede3d910461dda41781c218b..174b3d8e67dd5f8831c5fc599c287b232f136117 100644 (file)
@@ -327,10 +327,21 @@ static int sof_compr_pointer(struct snd_soc_component *component,
                             struct snd_compr_stream *cstream,
                             struct snd_compr_tstamp *tstamp)
 {
+       u64 dai_posn;
+       struct snd_sof_pcm *spcm;
+       struct snd_soc_pcm_runtime *rtd = cstream->private_data;
        struct sof_compr_stream *sstream = cstream->runtime->private_data;
 
+       spcm = snd_sof_find_spcm_dai(component, rtd);
+       if (!spcm)
+               return -EINVAL;
+
+       dai_posn = spcm->stream[cstream->direction].posn.dai_posn;
+
        tstamp->sampling_rate = sstream->sampling_rate;
        tstamp->copied_total = sstream->copied_total;
+       tstamp->pcm_io_frames = div_u64(spcm->stream[cstream->direction].posn.dai_posn,
+                                       sstream->channels * sstream->sample_container_bytes);
 
        return 0;
 }