aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Wilson <ksattic@gmail.com>2015-09-15 11:36:00 -0700
committerSimon Wilson <ksattic@gmail.com>2015-09-15 11:36:00 -0700
commit33fe27c809e0fa67e14db9fec37c5f2ef849aecb (patch)
treece6d4ce00eaaf40ce2277c0b2df1b6e8dce8150e
parent8d6f1f3ed27c74b1d927889b5f7cfc6d76af1f2c (diff)
parent4cddf19dfcf65e6fb1277a3230fd0fe509ec7e81 (diff)
Merge pull request #48 from vinodkoul/wait_delay
Wait delay
-rw-r--r--include/tinyalsa/asoundlib.h6
-rw-r--r--pcm.c18
2 files changed, 23 insertions, 1 deletions
diff --git a/include/tinyalsa/asoundlib.h b/include/tinyalsa/asoundlib.h
index 584cfe1..8fb7c95 100644
--- a/include/tinyalsa/asoundlib.h
+++ b/include/tinyalsa/asoundlib.h
@@ -179,6 +179,9 @@ unsigned int pcm_bytes_to_frames(struct pcm *pcm, unsigned int bytes);
int pcm_get_htimestamp(struct pcm *pcm, unsigned int *avail,
struct timespec *tstamp);
+/* Returns the subdevice on which the pcm has been opened */
+unsigned int pcm_get_subdevice(struct pcm *pcm);
+
/* Write data to the fifo.
* Will start playback on the first write or on a write that
* occurs after a fifo underrun.
@@ -205,6 +208,9 @@ int pcm_stop(struct pcm *pcm);
int pcm_wait(struct pcm *pcm, int timeout);
+/* Get the pcm delay */
+long pcm_get_delay(struct pcm *pcm);
+
/*
* MIXER API
*/
diff --git a/pcm.c b/pcm.c
index a260bfe..2c1308d 100644
--- a/pcm.c
+++ b/pcm.c
@@ -170,6 +170,8 @@ struct pcm {
struct snd_pcm_sync_ptr *sync_ptr;
void *mmap_buffer;
unsigned int noirq_frames_per_msec;
+ long pcm_delay;
+ unsigned int subdevice;
};
unsigned int pcm_get_buffer_size(struct pcm *pcm)
@@ -182,6 +184,11 @@ const char* pcm_get_error(struct pcm *pcm)
return pcm->error;
}
+unsigned int pcm_get_subdevice(struct pcm *pcm)
+{
+ return pcm->subdevice;
+}
+
static int oops(struct pcm *pcm, int e, const char *fmt, ...)
{
va_list ap;
@@ -653,6 +660,7 @@ struct pcm *pcm_open(unsigned int card, unsigned int device,
oops(pcm, errno, "cannot get info");
goto fail_close;
}
+ pcm->subdevice = info.subdevice;
param_init(&params);
param_set_mask(&params, SNDRV_PCM_HW_PARAM_FORMAT,
@@ -918,7 +926,7 @@ int pcm_wait(struct pcm *pcm, int timeout)
int err;
pfd.fd = pcm->fd;
- pfd.events = POLLOUT | POLLERR | POLLNVAL;
+ pfd.events = POLLIN | POLLOUT | POLLERR | POLLNVAL;
do {
/* let's wait for avail or timeout */
@@ -1046,3 +1054,11 @@ int pcm_mmap_read(struct pcm *pcm, void *data, unsigned int count)
return pcm_mmap_transfer(pcm, data, count);
}
+
+long pcm_get_delay(struct pcm *pcm)
+{
+ if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_DELAY, &pcm->pcm_delay) < 0)
+ return -1;
+
+ return pcm->pcm_delay;
+}