From 9e2c240f20f82159b59c37ed3c722c1279f7863e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Boisnard?= Date: Tue, 17 Sep 2013 22:43:18 +0200 Subject: Add a function to disambiguate duplicate control names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Control names are not unique and can be shared by multiple mixers controls. When this happens, there is no way of accessing the mixer using its control name, because mixer_get_ctl_by_name() always returns the first match. The only way of accessing the mixer is through its control number, i.e. using mixer_get_ctl(). This patch adds the function mixer_get_ctl_by_name_and_index() to offer the possibility to retrieve a control through its name and index. This index corresponds to the nth occurence of the control name in the global supported controls names list. Change-Id: Ie29bf2a949ecf69f106bbe359155cdbfbe98928c Signed-off-by: Frédéric Boisnard Signed-off-by: David Wagner Signed-off-by: Bruce Beare Signed-off-by: Jack Ren Author-Tracking-BZ: 139255 --- mixer.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'mixer.c') diff --git a/mixer.c b/mixer.c index 4568cca..afe9d7f 100644 --- a/mixer.c +++ b/mixer.c @@ -191,6 +191,13 @@ 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) +{ + return mixer_get_ctl_by_name_and_index(mixer, name, 0); +} + +struct mixer_ctl *mixer_get_ctl_by_name_and_index(struct mixer *mixer, + const char *name, + unsigned int index) { unsigned int n; @@ -199,7 +206,8 @@ struct mixer_ctl *mixer_get_ctl_by_name(struct mixer *mixer, const char *name) for (n = 0; n < mixer->count; n++) if (!strcmp(name, (char*) mixer->elem_info[n].id.name)) - return mixer->ctl + n; + if (index-- == 0) + return mixer->ctl + n; return NULL; } -- cgit v1.2.3