From 558e594ba24b34cfd7374cf706b834479324c917 Mon Sep 17 00:00:00 2001 From: Taylor Holberton Date: Sun, 4 Dec 2016 13:42:28 -0800 Subject: Added pcm_link and pcm_unlink functions The link function is necessary for time sychronization between multiple PCMs. --- include/tinyalsa/pcm.h | 4 ++++ src/pcm.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/tinyalsa/pcm.h b/include/tinyalsa/pcm.h index 1d84eed..9157b9b 100644 --- a/include/tinyalsa/pcm.h +++ b/include/tinyalsa/pcm.h @@ -288,6 +288,10 @@ int pcm_mmap_begin(struct pcm *pcm, void **areas, unsigned int *offset, unsigned int pcm_mmap_commit(struct pcm *pcm, unsigned int offset, unsigned int frames); +int pcm_link(struct pcm *pcm1, struct pcm *pcm2); + +int pcm_unlink(struct pcm *pcm); + int pcm_prepare(struct pcm *pcm); int pcm_start(struct pcm *pcm); diff --git a/src/pcm.c b/src/pcm.c index f879fe7..b69316a 100644 --- a/src/pcm.c +++ b/src/pcm.c @@ -1053,6 +1053,38 @@ int pcm_is_ready(const struct pcm *pcm) return pcm->fd >= 0; } +/** Links two PCMs. + * After this function is called, the two PCMs will prepare, start and stop in sync (at the same time). + * If an error occurs, the error message will be written to @p pcm1. + * @param pcm1 A PCM handle. + * @param pcm2 Another PCM handle. + * @return On success, zero; on failure, a negative number. + * @ingroup libtinyalsa-pcm + */ +int pcm_link(struct pcm *pcm1, struct pcm *pcm2) +{ + int err = ioctl(pcm1->fd, SNDRV_PCM_IOCTL_LINK, pcm2->fd); + if (err == -1) { + return oops(pcm1, errno, "cannot link PCM"); + } + return 0; +} + +/** Unlinks a PCM. + * @see @ref pcm_link + * @param pcm A PCM handle. + * @return On success, zero; on failure, a negative number. + * @ingroup libtinyalsa-pcm + */ +int pcm_unlink(struct pcm *pcm) +{ + int err = ioctl(pcm->fd, SNDRV_PCM_IOCTL_UNLINK); + if (err == -1) { + return oops(pcm, errno, "cannot unlink PCM"); + } + return 0; +} + /** Prepares a PCM, if it has not been prepared already. * @param pcm A PCM handle. * @return On success, zero; on failure, a negative number. -- cgit v1.2.3