alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: Richard Fitzgerald <rf@opensource.wolfsonmicro.com>
To: vinod.koul@intel.com
Cc: alsa-devel@alsa-project.org
Subject: Re: [PATCH TINYCOMPRESS 1/14 v2] compress: Add	function to get timestamp in samples
Date: Fri, 22 Feb 2013 15:56:18 +0000	[thread overview]
Message-ID: <20130222155618.GA21174@opensource.wolfsonmicro.com> (raw)
In-Reply-To: <20130210000227.GA31139@opensource.wolfsonmicro.com>

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.

---
 compress.c                          |   16 ++++++++++++++++
 include/tinycompress/tinycompress.h |   14 ++++++++++++++
 2 files changed, 30 insertions(+), 0 deletions(-)

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
-- 
1.7.2.5

  parent reply	other threads:[~2013-02-22 15:56 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-10  0:02 [PATCH TINYCOMPRESS 1/14] compress: Add function to get timestamp in samples Richard Fitzgerald
2013-02-11  6:34 ` Vinod Koul
2013-02-11 14:11   ` Pierre-Louis Bossart
2013-02-19 17:18     ` Richard Fitzgerald
2013-02-19 17:24   ` Richard Fitzgerald
2013-02-20  5:50     ` Vinod Koul
2013-02-22 15:56 ` Richard Fitzgerald [this message]
2013-02-22 18:09   ` [PATCH TINYCOMPRESS 1/14 v2] " Vinod Koul

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130222155618.GA21174@opensource.wolfsonmicro.com \
    --to=rf@opensource.wolfsonmicro.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=vinod.koul@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).