diff options
author | Rohit kumar <rohitkr@codeaurora.org> | 2020-06-02 11:14:38 +0530 |
---|---|---|
committer | Rohit kumar <rohitkr@codeaurora.org> | 2020-06-02 12:31:17 +0530 |
commit | f38405c4fd804fc3482055f1345095343ef243c5 (patch) | |
tree | afa8e91e4c19f4a1c929d928ec9764b3445ad7fa | |
parent | bdc1fcf5f04b1bc2f97e9d449ced1c516f70d4af (diff) |
mixer: Add plugin support for mixer_consume/read_event
snd_ctl_event is needed by client to get details of event received.
Introduce mixer_read_event() with plugin support to support this.
-rw-r--r-- | include/tinyalsa/mixer.h | 4 | ||||
-rw-r--r-- | src/mixer.c | 38 | ||||
-rw-r--r-- | src/mixer_hw.c | 9 |
3 files changed, 43 insertions, 8 deletions
diff --git a/include/tinyalsa/mixer.h b/include/tinyalsa/mixer.h index 6cd914a..7f0f022 100644 --- a/include/tinyalsa/mixer.h +++ b/include/tinyalsa/mixer.h @@ -35,7 +35,9 @@ #ifndef TINYALSA_MIXER_H #define TINYALSA_MIXER_H +#include <sys/time.h> #include <stddef.h> +#include <sound/asound.h> #if defined(__cplusplus) extern "C" { @@ -136,6 +138,8 @@ int mixer_ctl_get_range_min(const struct mixer_ctl *ctl); int mixer_ctl_get_range_max(const struct mixer_ctl *ctl); +int mixer_read_event(struct mixer *mixer, struct snd_ctl_event *ev); + int mixer_consume_event(struct mixer *mixer); #if defined(__cplusplus) } /* extern "C" */ diff --git a/src/mixer.c b/src/mixer.c index c8c6c2a..582d8c1 100644 --- a/src/mixer.c +++ b/src/mixer.c @@ -545,15 +545,37 @@ int mixer_wait_event(struct mixer *mixer, int timeout) * @returns 0 on success. -errno on failure. * @ingroup libtinyalsa-mixer */ -int mixer_consume_event(struct mixer *mixer) { +int mixer_consume_event(struct mixer *mixer) +{ struct snd_ctl_event ev; - ssize_t count = read(mixer->fd, &ev, sizeof(ev)); - // Exporting the actual event would require exposing snd_ctl_event - // via the header file, and all associated structs. - // The events generally tell you exactly which value changed, - // but reading values you're interested isn't hard and simplifies - // the interface greatly. - return (count >= 0) ? 0 : -errno; + + return mixer_read_event(mixer, &ev); +} + +int mixer_read_event(struct mixer *mixer, struct snd_ctl_event *ev) +{ + struct mixer_ctl_group *grp; + ssize_t count = 0; + + if (mixer->h_grp) { + grp = mixer->h_grp; + if (grp->event_cnt) { + grp->event_cnt--; + count = grp->ops->read_event(grp->data, ev, sizeof(*ev)); + return (count >= 0) ? 0 : -errno; + } + } +#ifdef TINYALSA_USES_PLUGINS + if (mixer->v_grp) { + grp = mixer->v_grp; + if (grp->event_cnt) { + grp->event_cnt--; + count = grp->ops->read_event(grp->data, ev, sizeof(*ev)); + return (count >= 0) ? 0 : -errno; + } + } +#endif + return 0; } static unsigned int mixer_grp_get_count(struct mixer_ctl_group *grp) diff --git a/src/mixer_hw.c b/src/mixer_hw.c index 2e86dfa..da5a390 100644 --- a/src/mixer_hw.c +++ b/src/mixer_hw.c @@ -82,9 +82,18 @@ static int mixer_hw_ioctl(void *data, unsigned int cmd, ...) return ioctl(hw_data->fd, cmd, arg); } +static ssize_t mixer_hw_read_event(void *data, struct snd_ctl_event *ev, + size_t size) +{ + struct mixer_hw_data *hw_data = data; + + return read(hw_data->fd, ev, size); +} + static const struct mixer_ops mixer_hw_ops = { .close = mixer_hw_close, .ioctl = mixer_hw_ioctl, + .read_event = mixer_hw_read_event, }; int mixer_hw_open(unsigned int card, void **data, |