aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlenn Kasten2013-08-22 17:11:48 -0500
committerGlenn Kasten2013-08-30 15:15:34 -0500
commit6b0a206624ebe78cc10dba7015438371d1506de5 (patch)
treee738649349e6a1f995c7a103727d89a7848e7ef5
parent36ea2d824e5d8af550c139da9da20e73f82a9ae1 (diff)
downloadplatform-external-tinyalsa-6b0a206624ebe78cc10dba7015438371d1506de5.tar.gz
platform-external-tinyalsa-6b0a206624ebe78cc10dba7015438371d1506de5.tar.xz
platform-external-tinyalsa-6b0a206624ebe78cc10dba7015438371d1506de5.zip
pcm_get_htimestamp can now use CLOCK_MONOTONIC
Previously the timebase was not documented. Now a new pcm_open flag can be used to specify the clock. If flag PCM_MONOTONIC is specified, then pcm_open uses SNDRV_PCM_IOCTL_TTSTAMP with parameter SNDRV_PCM_TSTAMP_TYPE_MONOTONIC to request timestamps in CLOCK_MONOTONIC. Change-Id: I40ce359cb38d686cbb2521fb0602a8a17ab4f925
-rw-r--r--include/tinyalsa/asoundlib.h3
-rw-r--r--pcm.c11
2 files changed, 14 insertions, 0 deletions
diff --git a/include/tinyalsa/asoundlib.h b/include/tinyalsa/asoundlib.h
index 9c23e6e..41a8f06 100644
--- a/include/tinyalsa/asoundlib.h
+++ b/include/tinyalsa/asoundlib.h
@@ -55,6 +55,7 @@ struct pcm;
55 * second call to pcm_write will attempt to 55 * second call to pcm_write will attempt to
56 * restart the stream. 56 * restart the stream.
57 */ 57 */
58#define PCM_MONOTONIC 0x00000008 /* see pcm_get_htimestamp */
58 59
59/* PCM runtime states */ 60/* PCM runtime states */
60#define PCM_STATE_OPEN 0 61#define PCM_STATE_OPEN 0
@@ -172,6 +173,8 @@ unsigned int pcm_bytes_to_frames(struct pcm *pcm, unsigned int bytes);
172unsigned int pcm_get_latency(struct pcm *pcm); 173unsigned int pcm_get_latency(struct pcm *pcm);
173 174
174/* Returns available frames in pcm buffer and corresponding time stamp. 175/* Returns available frames in pcm buffer and corresponding time stamp.
176 * The clock is CLOCK_MONOTONIC if flag PCM_MONOTONIC was specified in pcm_open,
177 * otherwise the clock is CLOCK_REALTIME.
175 * For an input stream, frames available are frames ready for the 178 * For an input stream, frames available are frames ready for the
176 * application to read. 179 * application to read.
177 * For an output stream, frames available are the number of empty frames available 180 * For an output stream, frames available are the number of empty frames available
diff --git a/pcm.c b/pcm.c
index 3006d6b..b7aba00 100644
--- a/pcm.c
+++ b/pcm.c
@@ -736,6 +736,17 @@ struct pcm *pcm_open(unsigned int card, unsigned int device,
736 goto fail; 736 goto fail;
737 } 737 }
738 738
739#ifdef SNDRV_PCM_IOCTL_TTSTAMP
740 if (pcm->flags & PCM_MONOTONIC) {
741 int arg = SNDRV_PCM_TSTAMP_TYPE_MONOTONIC;
742 rc = ioctl(pcm->fd, SNDRV_PCM_IOCTL_TTSTAMP, &arg);
743 if (rc < 0) {
744 oops(pcm, rc, "cannot set timestamp type");
745 goto fail;
746 }
747 }
748#endif
749
739 pcm->underruns = 0; 750 pcm->underruns = 0;
740 return pcm; 751 return pcm;
741 752