From: Richard Fitzgerald Date: Fri, 22 Feb 2013 15:56:18 +0000 (+0000) Subject: compress: Add function to get timestamp in samples X-Git-Tag: v0.1.0~14 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=0d20d8bca2babf051db11a0ca47bf7485801f8e0;p=tinycompress.git compress: Add function to get timestamp in samples The compress_get_hpointer() converts the timestamp into actual time. But Android needs it in samples. To avoid the inefficiency of using compress_get_hpointer() and converting into time and then back into samples, this change adds compress_get_tstamp() which returns the raw sample count. Signed-off-by: Vinod Koul --- diff --git a/compress.c b/compress.c index 27c03d9..01fb3f0 100644 --- a/compress.c +++ b/compress.c @@ -296,6 +296,22 @@ int compress_get_hpointer(struct compress *compress, return 0; } +int compress_get_tstamp(struct compress *compress, + unsigned long *samples, unsigned int *sampling_rate) +{ + struct snd_compr_tstamp ktstamp; + + if (!is_compress_ready(compress)) + return oops(compress, -ENODEV, "device not ready"); + + if (ioctl(compress->fd, SNDRV_COMPRESS_TSTAMP, &ktstamp)) + return oops(compress, errno, "cannot get tstamp"); + + *samples = ktstamp.pcm_io_frames; + *sampling_rate = ktstamp.sampling_rate; + return 0; +} + int compress_write(struct compress *compress, char *buf, unsigned int size) { struct snd_compr_avail avail; diff --git a/include/tinycompress/tinycompress.h b/include/tinycompress/tinycompress.h index 13dea3e..b1fbc65 100644 --- a/include/tinycompress/tinycompress.h +++ b/include/tinycompress/tinycompress.h @@ -73,6 +73,7 @@ struct compr_config { #define COMPRESS_IN 0x10000000 struct compress; +struct snd_compr_tstamp; /* * compress_open: open a new compress stream @@ -103,6 +104,19 @@ void compress_close(struct compress *compress); */ int compress_get_hpointer(struct compress *compress, unsigned int *avail, struct timespec *tstamp); + + +/* + * compress_get_tstamp: get the raw hw timestamp + * 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_tstamp(struct compress *compress, + unsigned long *samples, unsigned int *sampling_rate); + /* * compress_write: write data to the compress stream * return bytes written on success, negative on error