[PATCH 0/2] ASoC: SOF: compress: Add support for timestamp on capture

The purpose of this patch series is to add support for timestamping on capture direction using the compress API.
This is simply done by splitting sof_compr_copy into 2 functions: sof_compr_copy_playback and sof_compr_copy_capture. Each of these functions handles one of the possible directions: capture or playback and is called in sof_compr_copy based on the stream's direction.
The only difference between sof_compr_copy_playback and sof_compr_copy_capture is the fact that on playback case we need to copy data from user space and on capture we need to copy data to user space.
Laurentiu Mihalcea (2): ASoC: SOF: compress: Move sof_compr_copy functionality ASoC: SOF: compress: Add copy function for capture case
sound/soc/sof/compress.c | 47 +++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 8 deletions(-)

Since we're preparing to add support for compress capture, we need to move the content of sof_compr_copy into a separate function which handles the playback direction just like the initial sof_compr_copy.
Reviewed-by: Paul Olaru paul.olaru@nxp.com Reviewed-by: Daniel Baluta daniel.baluta@nxp.com Signed-off-by: Laurentiu Mihalcea laurentiu.mihalcea@nxp.com --- sound/soc/sof/compress.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/sound/soc/sof/compress.c b/sound/soc/sof/compress.c index 174b3d8e67dd..1b0b8b43723b 100644 --- a/sound/soc/sof/compress.c +++ b/sound/soc/sof/compress.c @@ -297,18 +297,13 @@ static int sof_compr_trigger(struct snd_soc_component *component, &reply, sizeof(reply)); }
-static int sof_compr_copy(struct snd_soc_component *component, - struct snd_compr_stream *cstream, - char __user *buf, size_t count) +static int sof_compr_copy_playback(struct snd_compr_runtime *rtd, + char __user *buf, size_t count) { - struct snd_compr_runtime *rtd = cstream->runtime; - unsigned int offset, n; void *ptr; + unsigned int offset, n; int ret;
- if (count > rtd->buffer_size) - count = rtd->buffer_size; - div_u64_rem(rtd->total_bytes_available, rtd->buffer_size, &offset); ptr = rtd->dma_area + offset; n = rtd->buffer_size - offset; @@ -323,6 +318,18 @@ static int sof_compr_copy(struct snd_soc_component *component, return count - ret; }
+static int sof_compr_copy(struct snd_soc_component *component, + struct snd_compr_stream *cstream, + char __user *buf, size_t count) +{ + struct snd_compr_runtime *rtd = cstream->runtime; + + if (count > rtd->buffer_size) + count = rtd->buffer_size; + + return sof_compr_copy_playback(rtd, buf, count); +} + static int sof_compr_pointer(struct snd_soc_component *component, struct snd_compr_stream *cstream, struct snd_compr_tstamp *tstamp)

Added a new copy function used to copy data to user buffer in the case of compress capture.
Reviewed-by: Paul Olaru paul.olaru@nxp.com Reviewed-by: Daniel Baluta daniel.baluta@nxp.com Signed-off-by: Laurentiu Mihalcea laurentiu.mihalcea@nxp.com --- sound/soc/sof/compress.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-)
diff --git a/sound/soc/sof/compress.c b/sound/soc/sof/compress.c index 1b0b8b43723b..81202e4b7cb9 100644 --- a/sound/soc/sof/compress.c +++ b/sound/soc/sof/compress.c @@ -318,6 +318,27 @@ static int sof_compr_copy_playback(struct snd_compr_runtime *rtd, return count - ret; }
+static int sof_compr_copy_capture(struct snd_compr_runtime *rtd, + char __user *buf, size_t count) +{ + void *ptr; + unsigned int offset, n; + int ret; + + div_u64_rem(rtd->total_bytes_transferred, rtd->buffer_size, &offset); + ptr = rtd->dma_area + offset; + n = rtd->buffer_size - offset; + + if (count < n) { + ret = copy_to_user(buf, ptr, count); + } else { + ret = copy_to_user(buf, ptr, n); + ret += copy_to_user(buf + n, rtd->dma_area, count - n); + } + + return count - ret; +} + static int sof_compr_copy(struct snd_soc_component *component, struct snd_compr_stream *cstream, char __user *buf, size_t count) @@ -327,7 +348,10 @@ static int sof_compr_copy(struct snd_soc_component *component, if (count > rtd->buffer_size) count = rtd->buffer_size;
- return sof_compr_copy_playback(rtd, buf, count); + if (cstream->direction == SND_COMPRESS_PLAYBACK) + return sof_compr_copy_playback(rtd, buf, count); + else + return sof_compr_copy_capture(rtd, buf, count); }
static int sof_compr_pointer(struct snd_soc_component *component,

On Mon, 22 Aug 2022 13:15:00 +0300, Laurentiu Mihalcea wrote:
The purpose of this patch series is to add support for timestamping on capture direction using the compress API.
This is simply done by splitting sof_compr_copy into 2 functions: sof_compr_copy_playback and sof_compr_copy_capture. Each of these functions handles one of the possible directions: capture or playback and is called in sof_compr_copy based on the stream's direction.
[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
Thanks!
[1/2] ASoC: SOF: compress: Move sof_compr_copy functionality commit: 272ff8828f35658aace17e3227624fbbd68a6bcf [2/2] ASoC: SOF: compress: Add copy function for capture case commit: 1a01e19278022cd2f7daa7a065ed47c5022dbad9
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks, Mark
participants (2)
-
Laurentiu Mihalcea
-
Mark Brown