diff options
-rw-r--r-- | include/tinyalsa/asoundlib.h | 6 | ||||
-rw-r--r-- | pcm.c | 18 |
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 */ @@ -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(¶ms); param_set_mask(¶ms, 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; +} |