]> git.alsa-project.org Git - tinycompress.git/commitdiff
lib: introduce compress_get_hpointer64
authorJaroslav Kysela <perex@perex.cz>
Wed, 21 Jan 2026 10:58:43 +0000 (11:58 +0100)
committerJaroslav Kysela <perex@perex.cz>
Thu, 28 May 2026 14:34:09 +0000 (16:34 +0200)
Allow to pass unwrapped avail value to applications. Introduce
new compress_get_hpointer64() function and change callback
in ops.

Use UINT_MAX limiting rather than blind wrap like in the previous
code in compress_get_hpointer().

Closes: https://github.com/alsa-project/tinycompress/pull/31
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
include/tinycompress/compress_ops.h
include/tinycompress/tinycompress.h
src/lib/compress.c
src/lib/compress_hw.c

index 7eabeb3cb051b0265dde61ac2df2b2682593efc0..7a4ffc9e5a9fa57ed1b04a90fe8345d85228b7c5 100644 (file)
@@ -23,7 +23,7 @@ struct compress_ops {
                        unsigned int flags, struct compr_config *config);
        void (*close)(void *compress_data);
        int (*get_hpointer)(void *compress_data,
-                       unsigned int *avail, struct timespec *tstamp);
+                       unsigned long long *avail, struct timespec *tstamp);
        int (*get_tstamp)(void *compress_data,
                        unsigned long long *samples, unsigned int *sampling_rate);
        int (*write)(void *compress_data, const void *buf, size_t size);
index 8d9677bd19a10bd946c5fe3fcedad4cb4e0bb749..f954f251622a8fb452eeebfd039f8ba0d864684f 100644 (file)
@@ -139,6 +139,18 @@ int compress_get_hpointer(struct compress *compress,
                unsigned int *avail, struct timespec *tstamp);
 
 
+/*
+ * compress_get_hpointe64r: get the hw timestamp
+ * return 0 on success, negative on error
+ *
+ * @compress: compress stream on which query is made
+ * @avail: buffer availble for write/read, in bytes
+ * @tstamp: hw time
+ */
+int compress_get_hpointer64(struct compress *compress,
+               unsigned long long *avail, struct timespec *tstamp);
+
+
 /*
  * compress_get_tstamp: get the raw hw timestamp
  * return 0 on success, negative on error
index 0c537acfa99a63adbe926fc59eacb49d4ad26bca..d9ec77ae176cb4462950ebfafa359b834dffe2ce 100644 (file)
@@ -58,6 +58,7 @@
 #include <dlfcn.h>
 #include <stdio.h>
 #include <string.h>
+#include <limits.h>
 #include <sys/errno.h>
 #include <sys/time.h>
 #include "tinycompress/tinycompress.h"
@@ -202,6 +203,21 @@ void compress_close(struct compress *compress)
 
 int compress_get_hpointer(struct compress *compress,
                unsigned int *avail, struct timespec *tstamp)
+{
+       unsigned long long _avail;
+       int ret;
+
+       ret = compress->ops->get_hpointer(compress->data, &_avail, tstamp);
+       if (ret >= 0) {
+               if (_avail > UINT_MAX)
+                       _avail = UINT_MAX;
+               *avail = (unsigned int)_avail;
+       }
+       return ret;
+}
+
+int compress_get_hpointer64(struct compress *compress,
+               unsigned long long *avail, struct timespec *tstamp)
 {
        return compress->ops->get_hpointer(compress->data, avail, tstamp);
 }
index 6e372c51d1bea2c899ce634f5cbecd64595f16b6..1519d71ad579927934ba9f8061973adf37e2bcfb 100644 (file)
@@ -237,7 +237,7 @@ static void compress_hw_avail64_from_32(struct snd_compr_avail64 *avail64,
 }
 
 static int compress_hw_get_hpointer(void *data,
-               unsigned int *avail, struct timespec *tstamp)
+               unsigned long long *avail, struct timespec *tstamp)
 {
        struct compress_hw_data *compress = (struct compress_hw_data *)data;
        struct snd_compr_avail kavail32;
@@ -263,7 +263,7 @@ static int compress_hw_get_hpointer(void *data,
 
        if (0 == kavail64.tstamp.sampling_rate)
                return oops(compress, ENODATA, "sample rate unknown");
-       *avail = (unsigned int)kavail64.avail;
+       *avail = kavail64.avail;
        time = kavail64.tstamp.pcm_io_frames / kavail64.tstamp.sampling_rate;
        tstamp->tv_sec = time;
        time = kavail64.tstamp.pcm_io_frames % kavail64.tstamp.sampling_rate;