From: George Verhaegen Date: Mon, 21 Jul 2025 15:19:16 +0000 (+0100) Subject: compress_ops: add get_tstamp64 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=0bd5530be0b378038ec37719fa29508b7b6e6a37;p=tinycompress.git compress_ops: add get_tstamp64 Add get_tstamp64 using the new ioctl SNDRV_COMPRESS_TSTAMP64. --- diff --git a/include/tinycompress/compress_ops.h b/include/tinycompress/compress_ops.h index 2ee8d15..290a831 100644 --- a/include/tinycompress/compress_ops.h +++ b/include/tinycompress/compress_ops.h @@ -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); diff --git a/include/tinycompress/tinycompress.h b/include/tinycompress/tinycompress.h index a8b4e58..8d9677b 100644 --- a/include/tinycompress/tinycompress.h +++ b/include/tinycompress/tinycompress.h @@ -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 diff --git a/src/lib/compress.c b/src/lib/compress.c index 5a8fd04..cf0b295 100644 --- a/src/lib/compress.c +++ b/src/lib/compress.c @@ -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); diff --git a/src/lib/compress_hw.c b/src/lib/compress_hw.c index 5aabae0..2773639 100644 --- a/src/lib/compress_hw.c +++ b/src/lib/compress_hw.c @@ -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,