From 010121a131a8092ca7cfc9e219b6fb1e3f4346bf Mon Sep 17 00:00:00 2001 From: Pankaj Bharadiya Date: Wed, 11 Jan 2017 08:57:06 +0530 Subject: Tinyalsa: Add support to poll on alsa control ALSA controls support polling on the kcontrols, this is used in HD-A for jack notifcation. In tinyalsa we can use this for notfication from sound card for any events detected by DSP Change-Id: I4193809bfcdb60f4dc11e1c2ad6a07b29cfa80e9 Signed-off-by: Hardik T Shah Signed-off-by: Vinod Koul Signed-off-by: Pankaj Bharadiya --- src/mixer.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'src') diff --git a/src/mixer.c b/src/mixer.c index b7239fd..73fbc66 100644 --- a/src/mixer.c +++ b/src/mixer.c @@ -36,6 +36,7 @@ #include #include #include +#include #include @@ -302,6 +303,49 @@ unsigned int mixer_get_num_ctls_by_name(const struct mixer *mixer, const char *n return count; } +/** Subscribes for the mixer events. + * @param mixer A mixer handle. + * @param subscribe value indicating subscribe or unsubscribe for events + * @returns On success, zero. + * On failure, non-zero. + * @ingroup libtinyalsa-mixer + */ +int mixer_subscribe_events(struct mixer *mixer, int subscribe) +{ + if (ioctl(mixer->fd, SNDRV_CTL_IOCTL_SUBSCRIBE_EVENTS, &subscribe) < 0) { + return -1; + } + return 0; +} + +/** Wait for mixer events. + * @param mixer A mixer handle. + * @param timeout timout value + * @returns On success, zero. + * On failure, non-zero. + * @ingroup libtinyalsa-mixer + */ +int mixer_wait_event(struct mixer *mixer, int timeout) +{ + struct pollfd pfd; + + pfd.fd = mixer->fd; + pfd.events = POLLIN | POLLOUT | POLLERR | POLLNVAL; + + for (;;) { + int err; + err = poll(&pfd, 1, timeout); + if (err < 0) + return -errno; + if (!err) + return 0; + if (pfd.revents & (POLLERR | POLLNVAL)) + return -EIO; + if (pfd.revents & (POLLIN | POLLOUT)) + return 1; + } +} + /** Gets a mixer control handle, by the mixer control's id. * For non-const access, see @ref mixer_get_ctl * @param mixer An initialized mixer handle. -- cgit v1.2.3