mixer: Add mixer_ctl_get_id

Add a function to get an id of a control that can be
passed to mixer_get_ctl(). This can be used to lookup
a control by name and store its id for later use rather
than have the overhead of name lookup each time it is
used. Lookup by id is quick and avoids the disadvantage
that storing a pointer to the mixer_ctl object creates
a client with a dependency on the address of the internal
control array.

Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com>
This commit is contained in:
Richard Fitzgerald
2014-09-09 16:54:12 +01:00
parent f2a7b6d3d8
commit 57a877495e
2 changed files with 13 additions and 0 deletions
+1
View File
@@ -225,6 +225,7 @@ struct mixer_ctl *mixer_get_ctl(struct mixer *mixer, unsigned int id);
struct mixer_ctl *mixer_get_ctl_by_name(struct mixer *mixer, const char *name);
/* Get info about mixer controls */
unsigned int mixer_ctl_get_id(struct mixer_ctl *ctl);
const char *mixer_ctl_get_name(struct mixer_ctl *ctl);
enum mixer_ctl_type mixer_ctl_get_type(struct mixer_ctl *ctl);
const char *mixer_ctl_get_type_string(struct mixer_ctl *ctl);
+12
View File
@@ -33,6 +33,7 @@
#include <fcntl.h>
#include <errno.h>
#include <ctype.h>
#include <limits.h>
#include <sys/ioctl.h>
@@ -209,6 +210,17 @@ void mixer_ctl_update(struct mixer_ctl *ctl)
ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_INFO, ctl->info);
}
unsigned int mixer_ctl_get_id(struct mixer_ctl *ctl)
{
if (!ctl)
return UINT_MAX;
/* numid values start at 1, return a 0-base value that
* can be passed to mixer_get_ctl()
*/
return ctl->info->id.numid - 1;
}
const char *mixer_ctl_get_name(struct mixer_ctl *ctl)
{
if (!ctl)