From 5d5a57315054e8fd4c0c8f800a45540275d90512 Mon Sep 17 00:00:00 2001 From: Vinod Koul Date: Tue, 12 Jun 2012 22:42:17 +0530 Subject: [PATCH] compress: fix the timestamp calculation use u64 for extended range and also ensure that seconds and nano seconds are claculated seprately Signed-off-by: Namarta Kohli Signed-off-by: Vinod Koul --- compress.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/compress.c b/compress.c index f4cf05a..2e263a0 100644 --- a/compress.c +++ b/compress.c @@ -272,7 +272,7 @@ int compress_get_hpointer(struct compress *compress, unsigned int *avail, struct timespec *tstamp) { struct snd_compr_avail kavail; - size_t time; + __u64 time; if (!is_compress_ready(compress)) return oops(compress, -ENODEV, "device not ready"); @@ -280,11 +280,10 @@ int compress_get_hpointer(struct compress *compress, if (ioctl(compress->fd, SNDRV_COMPRESS_AVAIL, &kavail)) return oops(compress, errno, "cannot get avail"); *avail = (unsigned int)kavail.avail; - - time = (kavail.tstamp.pcm_io_frames) / kavail.tstamp.sampling_rate; + time = kavail.tstamp.pcm_io_frames / kavail.tstamp.sampling_rate; tstamp->tv_sec = time; - time = (kavail.tstamp.pcm_io_frames * 1000000000) / kavail.tstamp.sampling_rate; - tstamp->tv_nsec = time; + time = kavail.tstamp.pcm_io_frames % kavail.tstamp.sampling_rate; + tstamp->tv_nsec = time * 1000000000 / kavail.tstamp.sampling_rate; return 0; } -- 2.47.3