aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Chant <achant@google.com>2018-02-05 15:16:41 -0800
committerRohit kumar <rohitkr@codeaurora.org>2020-06-02 12:30:39 +0530
commitbdc1fcf5f04b1bc2f97e9d449ced1c516f70d4af (patch)
tree5dd46f55f931a289bdf50b27355275aabe115da6
parent6ef70e16da9c83db73861561d32830f6448db55d (diff)
tinyalsa: add mixer_consume_event
mixer_consume_event consumes subscribed events from the mixer in order to allow monitoring of mixer control value changed.
-rw-r--r--include/tinyalsa/mixer.h1
-rw-r--r--src/mixer.c21
2 files changed, 22 insertions, 0 deletions
diff --git a/include/tinyalsa/mixer.h b/include/tinyalsa/mixer.h
index faeb957..6cd914a 100644
--- a/include/tinyalsa/mixer.h
+++ b/include/tinyalsa/mixer.h
@@ -136,6 +136,7 @@ int mixer_ctl_get_range_min(const struct mixer_ctl *ctl);
int mixer_ctl_get_range_max(const struct mixer_ctl *ctl);
+int mixer_consume_event(struct mixer *mixer);
#if defined(__cplusplus)
} /* extern "C" */
#endif
diff --git a/src/mixer.c b/src/mixer.c
index 1c9e63b..c8c6c2a 100644
--- a/src/mixer.c
+++ b/src/mixer.c
@@ -535,6 +535,27 @@ int mixer_wait_event(struct mixer *mixer, int timeout)
}
}
+/** Consume a mixer event.
+ * If mixer_subscribe_events has been called,
+ * mixer_wait_event will identify when a control value has changed.
+ * This function will clear a single event from the mixer so that
+ * further events can be alerted.
+ *
+ * @param mixer A mixer handle.
+ * @returns 0 on success. -errno on failure.
+ * @ingroup libtinyalsa-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;
+}
+
static unsigned int mixer_grp_get_count(struct mixer_ctl_group *grp)
{
if (!grp)