mirror of
https://github.com/openharmony/third_party_tinyalsa.git
synced 2026-07-19 23:33:30 -04:00
Merge pull request #93 from bpankajl/mixer_wait_event
Tinyalsa: Add support to poll on alsa control
This commit is contained in:
@@ -90,6 +90,10 @@ struct mixer_ctl *mixer_get_ctl_by_name_and_index(struct mixer *mixer,
|
||||
const char *name,
|
||||
unsigned int index);
|
||||
|
||||
int mixer_subscribe_events(struct mixer *mixer, int subscribe);
|
||||
|
||||
int mixer_wait_event(struct mixer *mixer, int timeout);
|
||||
|
||||
unsigned int mixer_ctl_get_id(const struct mixer_ctl *ctl);
|
||||
|
||||
const char *mixer_ctl_get_name(const struct mixer_ctl *ctl);
|
||||
|
||||
+44
@@ -36,6 +36,7 @@
|
||||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
#include <time.h>
|
||||
#include <poll.h>
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user