]> git.alsa-project.org Git - tinycompress.git/commitdiff
compress_ops: add get_tstamp64
authorGeorge Verhaegen <verhaegen@google.com>
Mon, 21 Jul 2025 15:19:16 +0000 (16:19 +0100)
committerVinod Koul <3178504+vinodkoul@users.noreply.github.com>
Wed, 21 Jan 2026 06:29:57 +0000 (11:59 +0530)
Add get_tstamp64 using the new ioctl SNDRV_COMPRESS_TSTAMP64.

include/tinycompress/compress_ops.h
include/tinycompress/tinycompress.h
src/lib/compress.c
src/lib/compress_hw.c

index 2ee8d156475cd8ad59ef7378a33bf13f6880abc8..290a8311a69e58f9a957be4b7e5ed1d0d2d75d08 100644 (file)
@@ -23,6 +23,8 @@ struct compress_ops {
                        unsigned int *avail, struct timespec *tstamp);
        int (*get_tstamp)(void *compress_data,
                        unsigned int *samples, unsigned int *sampling_rate);
+       int (*get_tstamp64)(void *compress_data,
+                       unsigned long long *samples, unsigned int *sampling_rate);
        int (*write)(void *compress_data, const void *buf, size_t size);
        int (*read)(void *compress_data, void *buf, size_t size);
        int (*start)(void *compress_data);
index a8b4e589b9d5f130558a09d5e5e739c3485cefba..8d9677bd19a10bd946c5fe3fcedad4cb4e0bb749 100644 (file)
@@ -150,6 +150,17 @@ int compress_get_hpointer(struct compress *compress,
 int compress_get_tstamp(struct compress *compress,
                unsigned int *samples, unsigned int *sampling_rate);
 
+/*
+ * compress_get_tstamp64: get the raw hw timestamp in 64 bit
+ * return 0 on success, negative on error
+ *
+ * @compress: compress stream on which query is made
+ * @samples: number of decoded samples played
+ * @sampling_rate: sampling rate of decoded samples
+ */
+int compress_get_tstamp64(struct compress *compress,
+               unsigned long long *samples, unsigned int *sampling_rate);
+
 /*
  * compress_write: write data to the compress stream
  * return bytes written on success, negative on error
index 5a8fd04514c6b1299424ac2702ccd5e7d1d9bcfe..cf0b29516df447b094349f85c11976f985d34456 100644 (file)
@@ -205,6 +205,12 @@ int compress_get_tstamp(struct compress *compress,
        return compress->ops->get_tstamp(compress->data, samples, sampling_rate);
 }
 
+int compress_get_tstamp64(struct compress *compress,
+                       unsigned long long *samples, unsigned int *sampling_rate)
+{
+       return compress->ops->get_tstamp64(compress->data, samples, sampling_rate);
+}
+
 int compress_write(struct compress *compress, const void *buf, unsigned int size)
 {
        return compress->ops->write(compress->data, buf, size);
index 5aabae021aac3294f04ff172f3e705b81d27ceb7..277363948c6c1b0f8002ad72474395469be5eab6 100644 (file)
@@ -263,6 +263,23 @@ static int compress_hw_get_tstamp(void *data,
        return 0;
 }
 
+static int compress_hw_get_tstamp64(void *data,
+                       unsigned long long *samples, unsigned int *sampling_rate)
+{
+       struct compress_hw_data *compress = (struct compress_hw_data *)data;
+       struct snd_compr_tstamp64 ktstamp;
+
+       if (!is_compress_hw_ready(compress))
+               return oops(compress, ENODEV, "device not ready");
+
+       if (ioctl(compress->fd, SNDRV_COMPRESS_TSTAMP64, &ktstamp))
+               return oops(compress, errno, "cannot get tstamp64");
+
+       *samples = ktstamp.pcm_io_frames;
+       *sampling_rate = ktstamp.sampling_rate;
+       return 0;
+}
+
 static int compress_hw_write(void *data, const void *buf, size_t size)
 {
        struct compress_hw_data *compress = (struct compress_hw_data *)data;
@@ -603,6 +620,7 @@ struct compress_ops compress_hw_ops = {
        .close = compress_hw_close,
        .get_hpointer = compress_hw_get_hpointer,
        .get_tstamp = compress_hw_get_tstamp,
+       .get_tstamp64 = compress_hw_get_tstamp64,
        .write = compress_hw_write,
        .read = compress_hw_read,
        .start = compress_hw_start,