]> git.alsa-project.org Git - tinycompress.git/commitdiff
compress: Add function to get timestamp in samples
authorRichard Fitzgerald <rf@opensource.wolfsonmicro.com>
Fri, 22 Feb 2013 15:56:18 +0000 (15:56 +0000)
committerVinod Koul <vinod.koul@intel.com>
Fri, 22 Feb 2013 18:08:12 +0000 (23:38 +0530)
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 <vinod.koul@intel.com>
compress.c
include/tinycompress/tinycompress.h

index 27c03d9977090114d365046eb76b6b295173f1dd..01fb3f0fe9cf89a7ca7950690c1f89c7de49cdee 100644 (file)
@@ -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;
index 13dea3e4c014f6c787d37675e82a4465bb27b664..b1fbc65b057f018193e2355a39752b731cff374a 100644 (file)
@@ -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