[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250711093636.28204-3-verhaegen@google.com>
Date: Fri, 11 Jul 2025 10:36:28 +0100
From: Joris Verhaegen <verhaegen@...gle.com>
To: Vinod Koul <vkoul@...nel.org>, Jaroslav Kysela <perex@...ex.cz>, Takashi Iwai <tiwai@...e.com>,
Liam Girdwood <lgirdwood@...il.com>, Mark Brown <broonie@...nel.org>,
Charles Keepax <ckeepax@...nsource.cirrus.com>,
Richard Fitzgerald <rf@...nsource.cirrus.com>, David Rhodes <david.rhodes@...rus.com>,
Cezary Rojewski <cezary.rojewski@...el.com>, Peter Ujfalusi <peter.ujfalusi@...ux.intel.com>,
Bard Liao <yung-chuan.liao@...ux.intel.com>,
Ranjani Sridharan <ranjani.sridharan@...ux.intel.com>,
Kai Vehmanen <kai.vehmanen@...ux.intel.com>,
Pierre-Louis Bossart <pierre-louis.bossart@...ux.dev>, Srinivas Kandagatla <srini@...nel.org>,
Daniel Baluta <daniel.baluta@....com>, Orson Zhai <orsonzhai@...il.com>,
Baolin Wang <baolin.wang@...ux.alibaba.com>, Chunyan Zhang <zhang.lyra@...il.com>,
Kunihiko Hayashi <hayashi.kunihiko@...ionext.com>, Masami Hiramatsu <mhiramat@...nel.org>
Cc: Joris Verhaegen <verhaegen@...gle.com>, kernel-team@...roid.com,
linux-sound@...r.kernel.org, linux-kernel@...r.kernel.org,
patches@...nsource.cirrus.com, linux-arm-msm@...r.kernel.org,
sound-open-firmware@...a-project.org, linux-arm-kernel@...ts.infradead.org,
David Li <dvdli@...gle.com>, Miller Liang <millerliang@...gle.com>
Subject: [PATCH v2 2/4] ALSA: compress_offload: Add SNDRV_COMPRESS_TSTAMP64 ioctl
The previous patch introduced the internal infrastructure for handling
64-bit timestamps. This patch exposes this capability to user-space.
Define the new ioctl command SNDRV_COMPRESS_TSTAMP64, which allows
applications to fetch the overflow-safe struct snd_compr_tstamp64.
The ioctl dispatch table is updated to handle the new command by
calling a new snd_compr_tstamp64 handler, while the legacy path is
renamed to snd_compr_tstamp32 for clarity.
Signed-off-by: Joris Verhaegen <verhaegen@...gle.com>
Tested-by: Joris Verhaegen <verhaegen@...gle.com>
Reviewed-by: David Li <dvdli@...gle.com>
Reviewed-by: Miller Liang <millerliang@...gle.com>
---
include/uapi/sound/compress_offload.h | 2 ++
sound/core/compress_offload.c | 50 +++++++++++++++++++++++----
2 files changed, 45 insertions(+), 7 deletions(-)
diff --git a/include/uapi/sound/compress_offload.h b/include/uapi/sound/compress_offload.h
index abd0ea3f86ee..2758d9ee3d91 100644
--- a/include/uapi/sound/compress_offload.h
+++ b/include/uapi/sound/compress_offload.h
@@ -208,6 +208,7 @@ struct snd_compr_task_status {
* Note: only codec params can be changed runtime and stream params cant be
* SNDRV_COMPRESS_GET_PARAMS: Query codec params
* SNDRV_COMPRESS_TSTAMP: get the current timestamp value
+ * SNDRV_COMPRESS_TSTAMP64: get the current timestamp value in 64 bit format
* SNDRV_COMPRESS_AVAIL: get the current buffer avail value.
* This also queries the tstamp properties
* SNDRV_COMPRESS_PAUSE: Pause the running stream
@@ -230,6 +231,7 @@ struct snd_compr_task_status {
struct snd_compr_metadata)
#define SNDRV_COMPRESS_TSTAMP _IOR('C', 0x20, struct snd_compr_tstamp)
#define SNDRV_COMPRESS_AVAIL _IOR('C', 0x21, struct snd_compr_avail)
+#define SNDRV_COMPRESS_TSTAMP64 _IOR('C', 0x22, struct snd_compr_tstamp64)
#define SNDRV_COMPRESS_PAUSE _IO('C', 0x30)
#define SNDRV_COMPRESS_RESUME _IO('C', 0x31)
#define SNDRV_COMPRESS_START _IO('C', 0x32)
diff --git a/sound/core/compress_offload.c b/sound/core/compress_offload.c
index 6a8873bd62ae..40c1e69961b7 100644
--- a/sound/core/compress_offload.c
+++ b/sound/core/compress_offload.c
@@ -211,8 +211,8 @@ snd_compr_tstamp32_from_64(struct snd_compr_tstamp *tstamp32,
tstamp32->sampling_rate = tstamp64->sampling_rate;
}
-static int snd_compr_update_tstamp(struct snd_compr_stream *stream,
- struct snd_compr_tstamp *tstamp)
+static int snd_compr_update_tstamp32(struct snd_compr_stream *stream,
+ struct snd_compr_tstamp *tstamp)
{
u64 copied_total64;
struct snd_compr_tstamp64 tstamp64;
@@ -238,11 +238,30 @@ static int snd_compr_update_tstamp(struct snd_compr_stream *stream,
return 0;
}
+static int snd_compr_update_tstamp64(struct snd_compr_stream *stream,
+ struct snd_compr_tstamp64 *tstamp)
+{
+ int retval = snd_compr_get_tstamp64(stream, tstamp);
+
+ if (retval != 0)
+ return retval;
+
+ pr_debug("dsp consumed till %u total %llu bytes\n", tstamp->byte_offset,
+ tstamp->copied_total);
+
+ if (stream->direction == SND_COMPRESS_PLAYBACK)
+ stream->runtime->total_bytes_transferred = tstamp->copied_total;
+ else
+ stream->runtime->total_bytes_available = tstamp->copied_total;
+
+ return 0;
+}
+
static size_t snd_compr_calc_avail(struct snd_compr_stream *stream,
struct snd_compr_avail *avail)
{
memset(avail, 0, sizeof(*avail));
- snd_compr_update_tstamp(stream, &avail->tstamp);
+ snd_compr_update_tstamp32(stream, &avail->tstamp);
/* Still need to return avail even if tstamp can't be filled in */
if (stream->runtime->total_bytes_available == 0 &&
@@ -769,19 +788,34 @@ snd_compr_set_metadata(struct snd_compr_stream *stream, unsigned long arg)
return retval;
}
-static inline int
-snd_compr_tstamp(struct snd_compr_stream *stream, unsigned long arg)
+static inline int snd_compr_tstamp32(struct snd_compr_stream *stream,
+ unsigned long arg)
{
struct snd_compr_tstamp tstamp = {0};
int ret;
- ret = snd_compr_update_tstamp(stream, &tstamp);
+ ret = snd_compr_update_tstamp32(stream, &tstamp);
if (ret == 0)
ret = copy_to_user((struct snd_compr_tstamp __user *)arg,
&tstamp, sizeof(tstamp)) ? -EFAULT : 0;
return ret;
}
+static inline int snd_compr_tstamp64(struct snd_compr_stream *stream,
+ unsigned long arg)
+{
+ struct snd_compr_tstamp64 tstamp = { 0 };
+ int ret;
+
+ ret = snd_compr_update_tstamp64(stream, &tstamp);
+ if (ret == 0)
+ ret = copy_to_user((struct snd_compr_tstamp64 __user *)arg,
+ &tstamp, sizeof(tstamp)) ?
+ -EFAULT :
+ 0;
+ return ret;
+}
+
static int snd_compr_pause(struct snd_compr_stream *stream)
{
int retval;
@@ -1355,7 +1389,9 @@ static long snd_compr_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
switch (_IOC_NR(cmd)) {
case _IOC_NR(SNDRV_COMPRESS_TSTAMP):
- return snd_compr_tstamp(stream, arg);
+ return snd_compr_tstamp32(stream, arg);
+ case _IOC_NR(SNDRV_COMPRESS_TSTAMP64):
+ return snd_compr_tstamp64(stream, arg);
case _IOC_NR(SNDRV_COMPRESS_AVAIL):
return snd_compr_ioctl_avail(stream, arg);
case _IOC_NR(SNDRV_COMPRESS_PAUSE):
--
2.50.0.727.gbf7dc18ff4-goog
Powered by blists - more mailing lists