From: Jaroslav Kysela Date: Wed, 21 Jan 2026 10:58:43 +0000 (+0100) Subject: lib: introduce compress_get_hpointer64 X-Git-Tag: v1.2.16~23 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=724b1fc9893c2afccad19d197220552e05125b72;p=tinycompress.git lib: introduce compress_get_hpointer64 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 --- diff --git a/include/tinycompress/compress_ops.h b/include/tinycompress/compress_ops.h index 7eabeb3..7a4ffc9 100644 --- a/include/tinycompress/compress_ops.h +++ b/include/tinycompress/compress_ops.h @@ -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); diff --git a/include/tinycompress/tinycompress.h b/include/tinycompress/tinycompress.h index 8d9677b..f954f25 100644 --- a/include/tinycompress/tinycompress.h +++ b/include/tinycompress/tinycompress.h @@ -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 diff --git a/src/lib/compress.c b/src/lib/compress.c index 0c537ac..d9ec77a 100644 --- a/src/lib/compress.c +++ b/src/lib/compress.c @@ -58,6 +58,7 @@ #include #include #include +#include #include #include #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); } diff --git a/src/lib/compress_hw.c b/src/lib/compress_hw.c index 6e372c5..1519d71 100644 --- a/src/lib/compress_hw.c +++ b/src/lib/compress_hw.c @@ -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;