blob: 9e661c5d25fe9d271c743224c1f4739d342798e6 [file] [log] [blame]
Simon Wilson79d39652011-05-25 13:44:23 -07001/* mixer.c
2**
3** Copyright 2011, The Android Open Source Project
4**
5** Redistribution and use in source and binary forms, with or without
6** modification, are permitted provided that the following conditions are met:
7** * Redistributions of source code must retain the above copyright
8** notice, this list of conditions and the following disclaimer.
9** * Redistributions in binary form must reproduce the above copyright
10** notice, this list of conditions and the following disclaimer in the
11** documentation and/or other materials provided with the distribution.
12** * Neither the name of The Android Open Source Project nor the names of
13** its contributors may be used to endorse or promote products derived
14** from this software without specific prior written permission.
15**
16** THIS SOFTWARE IS PROVIDED BY The Android Open Source Project ``AS IS'' AND
17** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19** ARE DISCLAIMED. IN NO EVENT SHALL The Android Open Source Project BE LIABLE
20** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
26** DAMAGE.
27*/
28
29#include <stdio.h>
30#include <stdlib.h>
Ben Zhang7ed2ffb2016-04-22 17:59:40 -070031#include <stdint.h>
Simon Wilson79d39652011-05-25 13:44:23 -070032#include <string.h>
33#include <unistd.h>
34#include <fcntl.h>
35#include <errno.h>
36#include <ctype.h>
Richard Fitzgerald57a87742014-09-09 16:54:12 +010037#include <limits.h>
Dima Krasner696c4482016-03-05 19:50:02 +020038#include <time.h>
Simon Wilson79d39652011-05-25 13:44:23 -070039
Simon Wilson6a52f2c2012-05-04 16:32:10 -070040#include <sys/ioctl.h>
41
Simon Wilson79d39652011-05-25 13:44:23 -070042#include <linux/ioctl.h>
43#define __force
44#define __bitwise
45#define __user
46#include <sound/asound.h>
47
Ricardo Biehl Pasquali04952ee2016-10-05 20:32:09 -030048#include <tinyalsa/mixer.h>
Simon Wilson79d39652011-05-25 13:44:23 -070049
Taylor Holberton7c8b20a2016-10-01 19:25:19 -040050/** A mixer control.
Taylor Holberton8ae5d112016-11-19 10:35:25 -080051 * @ingroup libtinyalsa-mixer
Taylor Holberton7c8b20a2016-10-01 19:25:19 -040052 */
Simon Wilson79d39652011-05-25 13:44:23 -070053struct mixer_ctl {
Taylor Holberton7c8b20a2016-10-01 19:25:19 -040054 /** The mixer that the mixer control belongs to */
Simon Wilson79d39652011-05-25 13:44:23 -070055 struct mixer *mixer;
Taylor Holbertonad4d7d72016-11-23 13:34:18 -080056 /** Information on the control's value (i.e. type, number of values) */
Richard Fitzgerald899cece2014-09-09 17:03:21 +010057 struct snd_ctl_elem_info info;
Taylor Holbertonad4d7d72016-11-23 13:34:18 -080058 /** A list of string representations of enumerated values (only valid for enumerated controls) */
Simon Wilson79d39652011-05-25 13:44:23 -070059 char **ename;
60};
61
Taylor Holberton7c8b20a2016-10-01 19:25:19 -040062/** A mixer handle.
Taylor Holberton8ae5d112016-11-19 10:35:25 -080063 * @ingroup libtinyalsa-mixer
Taylor Holberton7c8b20a2016-10-01 19:25:19 -040064 */
Simon Wilson79d39652011-05-25 13:44:23 -070065struct mixer {
Taylor Holberton7c8b20a2016-10-01 19:25:19 -040066 /** File descriptor for the card */
Simon Wilson79d39652011-05-25 13:44:23 -070067 int fd;
Taylor Holberton7c8b20a2016-10-01 19:25:19 -040068 /** Card information */
Simon Wilsonec281392013-06-28 16:21:31 -070069 struct snd_ctl_card_info card_info;
Taylor Holberton7c8b20a2016-10-01 19:25:19 -040070 /** A continuous array of mixer controls */
Simon Wilson79d39652011-05-25 13:44:23 -070071 struct mixer_ctl *ctl;
Taylor Holberton7c8b20a2016-10-01 19:25:19 -040072 /** The number of mixer controls */
Simon Wilson79d39652011-05-25 13:44:23 -070073 unsigned int count;
74};
75
Taylor Holberton7c8b20a2016-10-01 19:25:19 -040076/** Closes a mixer returned by @ref mixer_open.
77 * @param mixer A mixer handle.
Taylor Holberton8ae5d112016-11-19 10:35:25 -080078 * @ingroup libtinyalsa-mixer
Taylor Holberton7c8b20a2016-10-01 19:25:19 -040079 */
Simon Wilson79d39652011-05-25 13:44:23 -070080void mixer_close(struct mixer *mixer)
81{
82 unsigned int n,m;
83
Simon Wilson193b1c32011-06-07 23:42:38 -070084 if (!mixer)
Simon Wilsond2cb5032011-06-04 00:57:17 -070085 return;
Simon Wilsond2cb5032011-06-04 00:57:17 -070086
Simon Wilson79d39652011-05-25 13:44:23 -070087 if (mixer->fd >= 0)
88 close(mixer->fd);
89
90 if (mixer->ctl) {
91 for (n = 0; n < mixer->count; n++) {
92 if (mixer->ctl[n].ename) {
Richard Fitzgerald899cece2014-09-09 17:03:21 +010093 unsigned int max = mixer->ctl[n].info.value.enumerated.items;
Simon Wilson79d39652011-05-25 13:44:23 -070094 for (m = 0; m < max; m++)
95 free(mixer->ctl[n].ename[m]);
96 free(mixer->ctl[n].ename);
97 }
98 }
99 free(mixer->ctl);
100 }
101
Simon Wilson79d39652011-05-25 13:44:23 -0700102 free(mixer);
103
104 /* TODO: verify frees */
105}
106
Taylor Holberton7c8b20a2016-10-01 19:25:19 -0400107/** Opens a mixer for a given card.
108 * @param card The card to open the mixer for.
Taylor Holbertonb7a28572016-11-19 23:45:00 -0500109 * @returns An initialized mixer handle.
Taylor Holberton8ae5d112016-11-19 10:35:25 -0800110 * @ingroup libtinyalsa-mixer
Taylor Holberton7c8b20a2016-10-01 19:25:19 -0400111 */
Simon Wilson1bd580f2011-06-02 15:58:41 -0700112struct mixer *mixer_open(unsigned int card)
Simon Wilson79d39652011-05-25 13:44:23 -0700113{
114 struct snd_ctl_elem_list elist;
Simon Wilson79d39652011-05-25 13:44:23 -0700115 struct snd_ctl_elem_id *eid = NULL;
116 struct mixer *mixer = NULL;
Taylor Holberton6a38d5f2016-10-03 21:07:39 -0400117 unsigned int n;
Simon Wilson79d39652011-05-25 13:44:23 -0700118 int fd;
Simon Wilson1bd580f2011-06-02 15:58:41 -0700119 char fn[256];
Simon Wilson79d39652011-05-25 13:44:23 -0700120
Simon Wilson1bd580f2011-06-02 15:58:41 -0700121 snprintf(fn, sizeof(fn), "/dev/snd/controlC%u", card);
122 fd = open(fn, O_RDWR);
Simon Wilson79d39652011-05-25 13:44:23 -0700123 if (fd < 0)
124 return 0;
125
126 memset(&elist, 0, sizeof(elist));
127 if (ioctl(fd, SNDRV_CTL_IOCTL_ELEM_LIST, &elist) < 0)
128 goto fail;
129
130 mixer = calloc(1, sizeof(*mixer));
131 if (!mixer)
132 goto fail;
133
134 mixer->ctl = calloc(elist.count, sizeof(struct mixer_ctl));
Richard Fitzgerald899cece2014-09-09 17:03:21 +0100135 if (!mixer->ctl)
Simon Wilsonec281392013-06-28 16:21:31 -0700136 goto fail;
137
138 if (ioctl(fd, SNDRV_CTL_IOCTL_CARD_INFO, &mixer->card_info) < 0)
Simon Wilson79d39652011-05-25 13:44:23 -0700139 goto fail;
140
141 eid = calloc(elist.count, sizeof(struct snd_ctl_elem_id));
142 if (!eid)
143 goto fail;
144
145 mixer->count = elist.count;
146 mixer->fd = fd;
147 elist.space = mixer->count;
148 elist.pids = eid;
149 if (ioctl(fd, SNDRV_CTL_IOCTL_ELEM_LIST, &elist) < 0)
150 goto fail;
151
152 for (n = 0; n < mixer->count; n++) {
Richard Fitzgerald899cece2014-09-09 17:03:21 +0100153 struct snd_ctl_elem_info *ei = &mixer->ctl[n].info;
Simon Wilson79d39652011-05-25 13:44:23 -0700154 ei->id.numid = eid[n].numid;
155 if (ioctl(fd, SNDRV_CTL_IOCTL_ELEM_INFO, ei) < 0)
156 goto fail;
Simon Wilson79d39652011-05-25 13:44:23 -0700157 mixer->ctl[n].mixer = mixer;
Simon Wilson79d39652011-05-25 13:44:23 -0700158 }
159
160 free(eid);
161 return mixer;
162
163fail:
164 /* TODO: verify frees in failure case */
165 if (eid)
166 free(eid);
167 if (mixer)
168 mixer_close(mixer);
169 else if (fd >= 0)
170 close(fd);
171 return 0;
172}
173
Taylor Holbertonb7a28572016-11-19 23:45:00 -0500174/** Gets the name of the mixer's card.
175 * @param mixer An initialized mixer handle.
176 * @returns The name of the mixer's card.
177 * @ingroup libtinyalsa-mixer
178 */
Taylor Holbertoncac43a22016-12-01 18:11:24 -0800179const char *mixer_get_name(const struct mixer *mixer)
Simon Wilsonec281392013-06-28 16:21:31 -0700180{
181 return (const char *)mixer->card_info.name;
182}
183
Taylor Holbertonb7a28572016-11-19 23:45:00 -0500184/** Gets the number of mixer controls for a given mixer.
185 * @param mixer An initialized mixer handle.
186 * @returns The number of mixer controls for the given mixer.
187 * @ingroup libtinyalsa-mixer
188 */
Taylor Holbertoncac43a22016-12-01 18:11:24 -0800189unsigned int mixer_get_num_ctls(const struct mixer *mixer)
Simon Wilson79d39652011-05-25 13:44:23 -0700190{
Simon Wilson193b1c32011-06-07 23:42:38 -0700191 if (!mixer)
Simon Wilson98c1f162011-06-07 16:12:32 -0700192 return 0;
Simon Wilsond2cb5032011-06-04 00:57:17 -0700193
Simon Wilson79d39652011-05-25 13:44:23 -0700194 return mixer->count;
195}
196
Taylor Holberton94c7c832016-12-01 18:35:24 -0800197/** Gets the number of mixer controls, that go by a specified name, for a given mixer.
198 * @param mixer An initialized mixer handle.
199 * @param name The name of the mixer control
200 * @returns The number of mixer controls, specified by @p name, for the given mixer.
201 * @ingroup libtinyalsa-mixer
202 */
203unsigned int mixer_get_num_ctls_by_name(const struct mixer *mixer, const char *name)
204{
205 unsigned int n;
206 unsigned int count = 0;
207 struct mixer_ctl *ctl;
208
209 if (!mixer)
210 return 0;
211
212 ctl = mixer->ctl;
213
214 for (n = 0; n < mixer->count; n++)
215 if (!strcmp(name, (char*) ctl[n].info.id.name))
216 count++;
217
218 return count;
219}
220
Taylor Holbertonb7a28572016-11-19 23:45:00 -0500221/** Gets a mixer control handle, by the mixer control's id.
Taylor Holbertona94295b2016-12-01 18:23:16 -0800222 * For non-const access, see @ref mixer_get_ctl
223 * @param mixer An initialized mixer handle.
224 * @param id The control's id in the given mixer.
225 * @returns A handle to the mixer control.
226 * @ingroup libtinyalsa-mixer
227 */
228const struct mixer_ctl *mixer_get_ctl_const(const struct mixer *mixer, unsigned int id)
229{
230 if (mixer && (id < mixer->count))
231 return mixer->ctl + id;
232
233 return NULL;
234}
235
236/** Gets a mixer control handle, by the mixer control's id.
237 * For const access, see @ref mixer_get_ctl_const
Taylor Holbertonb7a28572016-11-19 23:45:00 -0500238 * @param mixer An initialized mixer handle.
239 * @param id The control's id in the given mixer.
240 * @returns A handle to the mixer control.
241 * @ingroup libtinyalsa-mixer
242 */
Simon Wilson79d39652011-05-25 13:44:23 -0700243struct mixer_ctl *mixer_get_ctl(struct mixer *mixer, unsigned int id)
244{
Simon Wilson98c1f162011-06-07 16:12:32 -0700245 if (mixer && (id < mixer->count))
Simon Wilson79d39652011-05-25 13:44:23 -0700246 return mixer->ctl + id;
247
248 return NULL;
249}
250
Taylor Holbertonb7a28572016-11-19 23:45:00 -0500251/** Gets the first instance of mixer control handle, by the mixer control's name.
252 * @param mixer An initialized mixer handle.
253 * @param name The control's name in the given mixer.
254 * @returns A handle to the mixer control.
255 * @ingroup libtinyalsa-mixer
256 */
Simon Wilson79d39652011-05-25 13:44:23 -0700257struct mixer_ctl *mixer_get_ctl_by_name(struct mixer *mixer, const char *name)
258{
Frédéric Boisnard9e2c2402013-09-17 22:43:18 +0200259 return mixer_get_ctl_by_name_and_index(mixer, name, 0);
260}
261
Taylor Holbertonb7a28572016-11-19 23:45:00 -0500262/** Gets an instance of mixer control handle, by the mixer control's name and index.
263 * For instance, if two controls have the name of 'Volume', then and index of 1 would return the second control.
264 * @param mixer An initialized mixer handle.
265 * @param name The control's name in the given mixer.
266 * @param index The control's index.
267 * @returns A handle to the mixer control.
268 * @ingroup libtinyalsa-mixer
269 */
Frédéric Boisnard9e2c2402013-09-17 22:43:18 +0200270struct mixer_ctl *mixer_get_ctl_by_name_and_index(struct mixer *mixer,
271 const char *name,
272 unsigned int index)
273{
Simon Wilson79d39652011-05-25 13:44:23 -0700274 unsigned int n;
Svyatoslav Mishync7328362016-01-24 19:43:38 +0200275 struct mixer_ctl *ctl;
Simon Wilsond2cb5032011-06-04 00:57:17 -0700276
Simon Wilson98c1f162011-06-07 16:12:32 -0700277 if (!mixer)
Simon Wilson193b1c32011-06-07 23:42:38 -0700278 return NULL;
Simon Wilsond2cb5032011-06-04 00:57:17 -0700279
Svyatoslav Mishync7328362016-01-24 19:43:38 +0200280 ctl = mixer->ctl;
281
Simon Wilson79d39652011-05-25 13:44:23 -0700282 for (n = 0; n < mixer->count; n++)
Richard Fitzgerald899cece2014-09-09 17:03:21 +0100283 if (!strcmp(name, (char*) ctl[n].info.id.name))
Frédéric Boisnard9e2c2402013-09-17 22:43:18 +0200284 if (index-- == 0)
285 return mixer->ctl + n;
Simon Wilson79d39652011-05-25 13:44:23 -0700286
287 return NULL;
288}
289
Taylor Holbertonb7a28572016-11-19 23:45:00 -0500290/** Updates the control's info.
291 * This is useful for a program that may be idle for a period of time.
292 * @param ctl An initialized control handle.
293 * @ingroup libtinyalsa-mixer
294 */
Simon Wilson710df882013-06-28 16:17:50 -0700295void mixer_ctl_update(struct mixer_ctl *ctl)
296{
297 ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_INFO, ctl->info);
298}
299
Taylor Holbertonb7a28572016-11-19 23:45:00 -0500300/** Gets the control's ID.
301 * @param ctl An initialized control handle.
302 * @returns On success, the control's ID is returned.
303 * On error, UINT_MAX is returned instead.
304 * @ingroup libtinyalsa-mixer
305 */
Taylor Holbertoncac43a22016-12-01 18:11:24 -0800306unsigned int mixer_ctl_get_id(const struct mixer_ctl *ctl)
Richard Fitzgerald57a87742014-09-09 16:54:12 +0100307{
308 if (!ctl)
309 return UINT_MAX;
310
311 /* numid values start at 1, return a 0-base value that
312 * can be passed to mixer_get_ctl()
313 */
Richard Fitzgerald899cece2014-09-09 17:03:21 +0100314 return ctl->info.id.numid - 1;
Richard Fitzgerald57a87742014-09-09 16:54:12 +0100315}
316
Taylor Holbertonb7a28572016-11-19 23:45:00 -0500317/** Gets the name of the control.
318 * @param ctl An initialized control handle.
319 * @returns On success, the name of the control.
320 * On error, NULL.
321 * @ingroup libtinyalsa-mixer
322 */
Taylor Holbertoncac43a22016-12-01 18:11:24 -0800323const char *mixer_ctl_get_name(const struct mixer_ctl *ctl)
Simon Wilsond2cb5032011-06-04 00:57:17 -0700324{
Simon Wilsonb29ac1a2012-03-08 10:15:08 -0800325 if (!ctl)
326 return NULL;
Simon Wilsond2cb5032011-06-04 00:57:17 -0700327
Richard Fitzgerald899cece2014-09-09 17:03:21 +0100328 return (const char *)ctl->info.id.name;
Simon Wilsond2cb5032011-06-04 00:57:17 -0700329}
330
Taylor Holbertonb7a28572016-11-19 23:45:00 -0500331/** Gets the value type of the control.
332 * @param ctl An initialized control handle
333 * @returns On success, the type of mixer control.
334 * On failure, it returns @ref MIXER_CTL_TYPE_UNKNOWN
335 * @ingroup libtinyalsa-mixer
336 */
Taylor Holbertoncac43a22016-12-01 18:11:24 -0800337enum mixer_ctl_type mixer_ctl_get_type(const struct mixer_ctl *ctl)
Simon Wilsond2cb5032011-06-04 00:57:17 -0700338{
Simon Wilson193b1c32011-06-07 23:42:38 -0700339 if (!ctl)
Simon Wilsond2cb5032011-06-04 00:57:17 -0700340 return MIXER_CTL_TYPE_UNKNOWN;
Simon Wilsond2cb5032011-06-04 00:57:17 -0700341
Richard Fitzgerald899cece2014-09-09 17:03:21 +0100342 switch (ctl->info.type) {
Simon Wilsond2cb5032011-06-04 00:57:17 -0700343 case SNDRV_CTL_ELEM_TYPE_BOOLEAN: return MIXER_CTL_TYPE_BOOL;
344 case SNDRV_CTL_ELEM_TYPE_INTEGER: return MIXER_CTL_TYPE_INT;
345 case SNDRV_CTL_ELEM_TYPE_ENUMERATED: return MIXER_CTL_TYPE_ENUM;
346 case SNDRV_CTL_ELEM_TYPE_BYTES: return MIXER_CTL_TYPE_BYTE;
347 case SNDRV_CTL_ELEM_TYPE_IEC958: return MIXER_CTL_TYPE_IEC958;
348 case SNDRV_CTL_ELEM_TYPE_INTEGER64: return MIXER_CTL_TYPE_INT64;
349 default: return MIXER_CTL_TYPE_UNKNOWN;
350 };
351}
352
Taylor Holbertonb7a28572016-11-19 23:45:00 -0500353/** Gets the string that describes the value type of the control.
354 * @param ctl An initialized control handle
355 * @returns On success, a string describing type of mixer control.
356 * @ingroup libtinyalsa-mixer
357 */
Taylor Holbertoncac43a22016-12-01 18:11:24 -0800358const char *mixer_ctl_get_type_string(const struct mixer_ctl *ctl)
Simon Wilsond2cb5032011-06-04 00:57:17 -0700359{
Simon Wilson193b1c32011-06-07 23:42:38 -0700360 if (!ctl)
Simon Wilsond2cb5032011-06-04 00:57:17 -0700361 return "";
Simon Wilsond2cb5032011-06-04 00:57:17 -0700362
Richard Fitzgerald899cece2014-09-09 17:03:21 +0100363 switch (ctl->info.type) {
Simon Wilsond2cb5032011-06-04 00:57:17 -0700364 case SNDRV_CTL_ELEM_TYPE_BOOLEAN: return "BOOL";
365 case SNDRV_CTL_ELEM_TYPE_INTEGER: return "INT";
366 case SNDRV_CTL_ELEM_TYPE_ENUMERATED: return "ENUM";
367 case SNDRV_CTL_ELEM_TYPE_BYTES: return "BYTE";
368 case SNDRV_CTL_ELEM_TYPE_IEC958: return "IEC958";
369 case SNDRV_CTL_ELEM_TYPE_INTEGER64: return "INT64";
370 default: return "Unknown";
371 };
372}
373
Taylor Holbertonb7a28572016-11-19 23:45:00 -0500374/** Gets the number of values in the control.
375 * @param ctl An initialized control handle
376 * @returns The number of values in the mixer control
377 * @ingroup libtinyalsa-mixer
378 */
Taylor Holbertoncac43a22016-12-01 18:11:24 -0800379unsigned int mixer_ctl_get_num_values(const struct mixer_ctl *ctl)
Simon Wilsond2cb5032011-06-04 00:57:17 -0700380{
Simon Wilson193b1c32011-06-07 23:42:38 -0700381 if (!ctl)
Simon Wilsond2cb5032011-06-04 00:57:17 -0700382 return 0;
Simon Wilsond2cb5032011-06-04 00:57:17 -0700383
Richard Fitzgerald899cece2014-09-09 17:03:21 +0100384 return ctl->info.count;
Simon Wilsond2cb5032011-06-04 00:57:17 -0700385}
386
Taylor Holbertoncac43a22016-12-01 18:11:24 -0800387static int percent_to_int(const struct snd_ctl_elem_info *ei, int percent)
Simon Wilson79d39652011-05-25 13:44:23 -0700388{
Baptiste Robert4a484e12013-09-12 15:37:53 +0200389 if ((percent > 100) || (percent < 0)) {
390 return -EINVAL;
391 }
Simon Wilson98c1f162011-06-07 16:12:32 -0700392
Baptiste Robert4a484e12013-09-12 15:37:53 +0200393 int range = (ei->value.integer.max - ei->value.integer.min);
Simon Wilson98c1f162011-06-07 16:12:32 -0700394
Simon Wilson79d39652011-05-25 13:44:23 -0700395 return ei->value.integer.min + (range * percent) / 100;
396}
397
Taylor Holbertoncac43a22016-12-01 18:11:24 -0800398static int int_to_percent(const struct snd_ctl_elem_info *ei, int value)
Simon Wilson79d39652011-05-25 13:44:23 -0700399{
400 int range = (ei->value.integer.max - ei->value.integer.min);
Simon Wilson98c1f162011-06-07 16:12:32 -0700401
Simon Wilson79d39652011-05-25 13:44:23 -0700402 if (range == 0)
403 return 0;
Simon Wilson98c1f162011-06-07 16:12:32 -0700404
Simon Wilson79d39652011-05-25 13:44:23 -0700405 return ((value - ei->value.integer.min) / range) * 100;
406}
407
Taylor Holberton4e557192016-11-23 11:48:06 -0800408/** Gets a percentage representation of a specified control value.
409 * @param ctl An initialized control handle.
410 * @param id The index of the value within the control.
411 * @returns On success, the percentage representation of the control value.
412 * On failure, -EINVAL is returned.
413 * @ingroup libtinyalsa-mixer
414 */
Taylor Holbertoncac43a22016-12-01 18:11:24 -0800415int mixer_ctl_get_percent(const struct mixer_ctl *ctl, unsigned int id)
Simon Wilson79d39652011-05-25 13:44:23 -0700416{
Richard Fitzgerald899cece2014-09-09 17:03:21 +0100417 if (!ctl || (ctl->info.type != SNDRV_CTL_ELEM_TYPE_INTEGER))
Simon Wilson193b1c32011-06-07 23:42:38 -0700418 return -EINVAL;
Simon Wilsona1bb1e02011-05-26 18:22:00 -0700419
Richard Fitzgerald899cece2014-09-09 17:03:21 +0100420 return int_to_percent(&ctl->info, mixer_ctl_get_value(ctl, id));
Simon Wilsona1bb1e02011-05-26 18:22:00 -0700421}
422
Taylor Holberton4e557192016-11-23 11:48:06 -0800423/** Sets the value of a control by percent, specified by the value index.
424 * @param ctl An initialized control handle.
425 * @param id The index of the value to set
426 * @param percent A percentage value between 0 and 100.
427 * @returns On success, zero is returned.
428 * On failure, non-zero is returned.
429 * @ingroup libtinyalsa-mixer
430 */
Simon Wilsond2cb5032011-06-04 00:57:17 -0700431int mixer_ctl_set_percent(struct mixer_ctl *ctl, unsigned int id, int percent)
Simon Wilsona1bb1e02011-05-26 18:22:00 -0700432{
Richard Fitzgerald899cece2014-09-09 17:03:21 +0100433 if (!ctl || (ctl->info.type != SNDRV_CTL_ELEM_TYPE_INTEGER))
Simon Wilson193b1c32011-06-07 23:42:38 -0700434 return -EINVAL;
Simon Wilsona1bb1e02011-05-26 18:22:00 -0700435
Richard Fitzgerald899cece2014-09-09 17:03:21 +0100436 return mixer_ctl_set_value(ctl, id, percent_to_int(&ctl->info, percent));
Simon Wilsona1bb1e02011-05-26 18:22:00 -0700437}
438
Taylor Holberton4e557192016-11-23 11:48:06 -0800439/** Gets the value of a control.
440 * @param ctl An initialized control handle.
441 * @param id The index of the control value.
442 * @returns On success, the specified value is returned.
443 * On failure, -EINVAL is returned.
444 * @ingroup libtinyalsa-mixer
445 */
Taylor Holbertoncac43a22016-12-01 18:11:24 -0800446int mixer_ctl_get_value(const struct mixer_ctl *ctl, unsigned int id)
Simon Wilsona1bb1e02011-05-26 18:22:00 -0700447{
Simon Wilson79d39652011-05-25 13:44:23 -0700448 struct snd_ctl_elem_value ev;
Simon Wilson193b1c32011-06-07 23:42:38 -0700449 int ret;
Simon Wilson79d39652011-05-25 13:44:23 -0700450
Richard Fitzgerald899cece2014-09-09 17:03:21 +0100451 if (!ctl || (id >= ctl->info.count))
Simon Wilson193b1c32011-06-07 23:42:38 -0700452 return -EINVAL;
Simon Wilsond2cb5032011-06-04 00:57:17 -0700453
Simon Wilson79d39652011-05-25 13:44:23 -0700454 memset(&ev, 0, sizeof(ev));
Richard Fitzgerald899cece2014-09-09 17:03:21 +0100455 ev.id.numid = ctl->info.id.numid;
Simon Wilson193b1c32011-06-07 23:42:38 -0700456 ret = ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_READ, &ev);
457 if (ret < 0)
458 return ret;
Simon Wilson79d39652011-05-25 13:44:23 -0700459
Richard Fitzgerald899cece2014-09-09 17:03:21 +0100460 switch (ctl->info.type) {
Simon Wilson79d39652011-05-25 13:44:23 -0700461 case SNDRV_CTL_ELEM_TYPE_BOOLEAN:
Simon Wilsond2cb5032011-06-04 00:57:17 -0700462 return !!ev.value.integer.value[id];
Simon Wilsona1bb1e02011-05-26 18:22:00 -0700463
464 case SNDRV_CTL_ELEM_TYPE_INTEGER:
Simon Wilsond2cb5032011-06-04 00:57:17 -0700465 return ev.value.integer.value[id];
Simon Wilson066c9f62011-06-05 18:23:05 -0700466
467 case SNDRV_CTL_ELEM_TYPE_ENUMERATED:
468 return ev.value.enumerated.item[id];
Simon Wilsona1bb1e02011-05-26 18:22:00 -0700469
Pierre-Louis Bossart52510162011-10-24 15:00:17 -0500470 case SNDRV_CTL_ELEM_TYPE_BYTES:
471 return ev.value.bytes.data[id];
472
Simon Wilson79d39652011-05-25 13:44:23 -0700473 default:
Simon Wilson193b1c32011-06-07 23:42:38 -0700474 return -EINVAL;
Simon Wilson79d39652011-05-25 13:44:23 -0700475 }
476
477 return 0;
478}
479
Taylor Holberton4e557192016-11-23 11:48:06 -0800480/** Gets the contents of a control's value array.
481 * @param ctl An initialized control handle.
482 * @param array A pointer to write the array data to.
483 * The size of this array must be equal to the number of items in the array
484 * multiplied by the size of each item.
485 * @param count The number of items in the array.
486 * This parameter must match the number of items in the control.
487 * The number of items in the control may be accessed via @ref mixer_ctl_get_num_values
488 * @returns On success, zero.
489 * On failure, non-zero.
490 * @ingroup libtinyalsa-mixer
491 */
Taylor Holbertoncac43a22016-12-01 18:11:24 -0800492int mixer_ctl_get_array(const struct mixer_ctl *ctl, void *array, size_t count)
Dimitris Papastamosf51c05b2012-05-28 13:40:33 +0100493{
494 struct snd_ctl_elem_value ev;
Mythri P K45b2d042014-08-18 15:39:36 +0530495 int ret = 0;
Simon Wilson38f87f32012-10-23 15:05:23 -0700496 size_t size;
497 void *source;
Dimitris Papastamosf51c05b2012-05-28 13:40:33 +0100498
Richard Fitzgerald899cece2014-09-09 17:03:21 +0100499 if (!ctl || (count > ctl->info.count) || !count || !array)
Dimitris Papastamosf51c05b2012-05-28 13:40:33 +0100500 return -EINVAL;
501
502 memset(&ev, 0, sizeof(ev));
Richard Fitzgerald899cece2014-09-09 17:03:21 +0100503 ev.id.numid = ctl->info.id.numid;
Dimitris Papastamosf51c05b2012-05-28 13:40:33 +0100504
Richard Fitzgerald899cece2014-09-09 17:03:21 +0100505 switch (ctl->info.type) {
Simon Wilson38f87f32012-10-23 15:05:23 -0700506 case SNDRV_CTL_ELEM_TYPE_BOOLEAN:
507 case SNDRV_CTL_ELEM_TYPE_INTEGER:
Mythri P K45b2d042014-08-18 15:39:36 +0530508 ret = ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_READ, &ev);
509 if (ret < 0)
510 return ret;
Simon Wilson38f87f32012-10-23 15:05:23 -0700511 size = sizeof(ev.value.integer.value[0]);
512 source = ev.value.integer.value;
513 break;
514
515 case SNDRV_CTL_ELEM_TYPE_BYTES:
Mythri P K45b2d042014-08-18 15:39:36 +0530516 /* check if this is new bytes TLV */
Richard Fitzgerald899cece2014-09-09 17:03:21 +0100517 if (ctl->info.access & SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE) {
Mythri P K45b2d042014-08-18 15:39:36 +0530518 struct snd_ctl_tlv *tlv;
519 int ret;
520
Ben Zhang7ed2ffb2016-04-22 17:59:40 -0700521 if (count > SIZE_MAX - sizeof(*tlv))
522 return -EINVAL;
Mythri P K45b2d042014-08-18 15:39:36 +0530523 tlv = calloc(1, sizeof(*tlv) + count);
Ben Zhang7ed2ffb2016-04-22 17:59:40 -0700524 if (!tlv)
525 return -ENOMEM;
Richard Fitzgerald899cece2014-09-09 17:03:21 +0100526 tlv->numid = ctl->info.id.numid;
Mythri P K45b2d042014-08-18 15:39:36 +0530527 tlv->length = count;
528 ret = ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_TLV_READ, tlv);
529
530 source = tlv->tlv;
531 memcpy(array, source, count);
532
533 free(tlv);
534
535 return ret;
536 } else {
537 ret = ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_READ, &ev);
538 if (ret < 0)
539 return ret;
540 size = sizeof(ev.value.bytes.data[0]);
541 source = ev.value.bytes.data;
542 break;
543 }
Simon Wilson38f87f32012-10-23 15:05:23 -0700544
545 default:
546 return -EINVAL;
547 }
548
549 memcpy(array, source, size * count);
Dimitris Papastamosf51c05b2012-05-28 13:40:33 +0100550
551 return 0;
552}
553
Taylor Holberton4e557192016-11-23 11:48:06 -0800554/** Sets the value of a control, specified by the value index.
555 * @param ctl An initialized control handle.
556 * @param id The index of the value within the control.
557 * @param value The value to set.
558 * This must be in a range specified by @ref mixer_ctl_get_range_min
559 * and @ref mixer_ctl_get_range_max.
560 * @returns On success, zero is returned.
561 * On failure, non-zero is returned.
562 * @ingroup libtinyalsa-mixer
563 */
Simon Wilson066c9f62011-06-05 18:23:05 -0700564int mixer_ctl_set_value(struct mixer_ctl *ctl, unsigned int id, int value)
Simon Wilson79d39652011-05-25 13:44:23 -0700565{
566 struct snd_ctl_elem_value ev;
Simon Wilson193b1c32011-06-07 23:42:38 -0700567 int ret;
Simon Wilsond2cb5032011-06-04 00:57:17 -0700568
Richard Fitzgerald899cece2014-09-09 17:03:21 +0100569 if (!ctl || (id >= ctl->info.count))
Simon Wilson193b1c32011-06-07 23:42:38 -0700570 return -EINVAL;
Simon Wilson79d39652011-05-25 13:44:23 -0700571
572 memset(&ev, 0, sizeof(ev));
Richard Fitzgerald899cece2014-09-09 17:03:21 +0100573 ev.id.numid = ctl->info.id.numid;
Simon Wilson193b1c32011-06-07 23:42:38 -0700574 ret = ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_READ, &ev);
575 if (ret < 0)
576 return ret;
Simon Wilsona1bb1e02011-05-26 18:22:00 -0700577
Richard Fitzgerald899cece2014-09-09 17:03:21 +0100578 switch (ctl->info.type) {
Simon Wilson79d39652011-05-25 13:44:23 -0700579 case SNDRV_CTL_ELEM_TYPE_BOOLEAN:
Simon Wilsond2cb5032011-06-04 00:57:17 -0700580 ev.value.integer.value[id] = !!value;
Simon Wilson79d39652011-05-25 13:44:23 -0700581 break;
582
Simon Wilsona1bb1e02011-05-26 18:22:00 -0700583 case SNDRV_CTL_ELEM_TYPE_INTEGER:
Baptiste Robert6cd7d5f2013-08-07 11:32:45 +0200584 if ((value < mixer_ctl_get_range_min(ctl)) ||
585 (value > mixer_ctl_get_range_max(ctl))) {
586 return -EINVAL;
587 }
588
Simon Wilsond2cb5032011-06-04 00:57:17 -0700589 ev.value.integer.value[id] = value;
Simon Wilson79d39652011-05-25 13:44:23 -0700590 break;
Simon Wilson79d39652011-05-25 13:44:23 -0700591
Simon Wilson066c9f62011-06-05 18:23:05 -0700592 case SNDRV_CTL_ELEM_TYPE_ENUMERATED:
593 ev.value.enumerated.item[id] = value;
594 break;
595
David.Coutherutce2b6342013-06-11 16:22:57 +0200596 case SNDRV_CTL_ELEM_TYPE_BYTES:
597 ev.value.bytes.data[id] = value;
598 break;
599
Simon Wilson79d39652011-05-25 13:44:23 -0700600 default:
Simon Wilson193b1c32011-06-07 23:42:38 -0700601 return -EINVAL;
Simon Wilson79d39652011-05-25 13:44:23 -0700602 }
Simon Wilsona1bb1e02011-05-26 18:22:00 -0700603
Simon Wilson79d39652011-05-25 13:44:23 -0700604 return ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_WRITE, &ev);
605}
606
Taylor Holberton4e557192016-11-23 11:48:06 -0800607/** Sets the contents of a control's value array.
608 * @param ctl An initialized control handle.
609 * @param array The array containing control values.
610 * @param count The number of values in the array.
611 * This must match the number of values in the control.
612 * The number of values in a control may be accessed via @ref mixer_ctl_get_num_values
613 * @returns On success, zero.
614 * On failure, non-zero.
615 * @ingroup libtinyalsa-mixer
616 */
Simon Wilson38f87f32012-10-23 15:05:23 -0700617int mixer_ctl_set_array(struct mixer_ctl *ctl, const void *array, size_t count)
Dimitris Papastamosf51c05b2012-05-28 13:40:33 +0100618{
619 struct snd_ctl_elem_value ev;
Simon Wilson38f87f32012-10-23 15:05:23 -0700620 size_t size;
621 void *dest;
Dimitris Papastamosf51c05b2012-05-28 13:40:33 +0100622
Richard Fitzgerald899cece2014-09-09 17:03:21 +0100623 if (!ctl || (count > ctl->info.count) || !count || !array)
Dimitris Papastamosf51c05b2012-05-28 13:40:33 +0100624 return -EINVAL;
625
626 memset(&ev, 0, sizeof(ev));
Richard Fitzgerald899cece2014-09-09 17:03:21 +0100627 ev.id.numid = ctl->info.id.numid;
Dimitris Papastamosf51c05b2012-05-28 13:40:33 +0100628
Richard Fitzgerald899cece2014-09-09 17:03:21 +0100629 switch (ctl->info.type) {
Simon Wilson38f87f32012-10-23 15:05:23 -0700630 case SNDRV_CTL_ELEM_TYPE_BOOLEAN:
631 case SNDRV_CTL_ELEM_TYPE_INTEGER:
632 size = sizeof(ev.value.integer.value[0]);
633 dest = ev.value.integer.value;
634 break;
635
636 case SNDRV_CTL_ELEM_TYPE_BYTES:
Mythri P K45b2d042014-08-18 15:39:36 +0530637 /* check if this is new bytes TLV */
Richard Fitzgerald899cece2014-09-09 17:03:21 +0100638 if (ctl->info.access & SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE) {
Mythri P K45b2d042014-08-18 15:39:36 +0530639 struct snd_ctl_tlv *tlv;
640 int ret = 0;
Ben Zhang7ed2ffb2016-04-22 17:59:40 -0700641 if (count > SIZE_MAX - sizeof(*tlv))
642 return -EINVAL;
Mythri P K45b2d042014-08-18 15:39:36 +0530643 tlv = calloc(1, sizeof(*tlv) + count);
Ben Zhang7ed2ffb2016-04-22 17:59:40 -0700644 if (!tlv)
645 return -ENOMEM;
Richard Fitzgerald899cece2014-09-09 17:03:21 +0100646 tlv->numid = ctl->info.id.numid;
Mythri P K45b2d042014-08-18 15:39:36 +0530647 tlv->length = count;
648 memcpy(tlv->tlv, array, count);
649
650 ret = ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_TLV_WRITE, tlv);
651 free(tlv);
652
653 return ret;
654 } else {
655 size = sizeof(ev.value.bytes.data[0]);
656 dest = ev.value.bytes.data;
657 }
Simon Wilson38f87f32012-10-23 15:05:23 -0700658 break;
659
660 default:
661 return -EINVAL;
662 }
663
664 memcpy(dest, array, size * count);
Dimitris Papastamosf51c05b2012-05-28 13:40:33 +0100665
666 return ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_WRITE, &ev);
667}
668
Taylor Holberton4e557192016-11-23 11:48:06 -0800669/** Gets the minimum value of an control.
670 * The control must have an integer type.
671 * The type of the control can be checked with @ref mixer_ctl_get_type.
672 * @param ctl An initialized control handle.
673 * @returns On success, the minimum value of the control.
674 * On failure, -EINVAL.
675 * @ingroup libtinyalsa-mixer
676 */
Taylor Holbertoncac43a22016-12-01 18:11:24 -0800677int mixer_ctl_get_range_min(const struct mixer_ctl *ctl)
Simon Wilsonb9d4f6b2011-06-06 14:41:02 -0700678{
Richard Fitzgerald899cece2014-09-09 17:03:21 +0100679 if (!ctl || (ctl->info.type != SNDRV_CTL_ELEM_TYPE_INTEGER))
Simon Wilson193b1c32011-06-07 23:42:38 -0700680 return -EINVAL;
Simon Wilsonb9d4f6b2011-06-06 14:41:02 -0700681
Richard Fitzgerald899cece2014-09-09 17:03:21 +0100682 return ctl->info.value.integer.min;
Simon Wilsonb9d4f6b2011-06-06 14:41:02 -0700683}
684
Taylor Holberton4e557192016-11-23 11:48:06 -0800685/** Gets the maximum value of an control.
686 * The control must have an integer type.
687 * The type of the control can be checked with @ref mixer_ctl_get_type.
688 * @param ctl An initialized control handle.
689 * @returns On success, the maximum value of the control.
690 * On failure, -EINVAL.
691 * @ingroup libtinyalsa-mixer
692 */
Taylor Holbertoncac43a22016-12-01 18:11:24 -0800693int mixer_ctl_get_range_max(const struct mixer_ctl *ctl)
Simon Wilsonb9d4f6b2011-06-06 14:41:02 -0700694{
Richard Fitzgerald899cece2014-09-09 17:03:21 +0100695 if (!ctl || (ctl->info.type != SNDRV_CTL_ELEM_TYPE_INTEGER))
Simon Wilson193b1c32011-06-07 23:42:38 -0700696 return -EINVAL;
Simon Wilsonb9d4f6b2011-06-06 14:41:02 -0700697
Richard Fitzgerald899cece2014-09-09 17:03:21 +0100698 return ctl->info.value.integer.max;
Simon Wilsonb9d4f6b2011-06-06 14:41:02 -0700699}
700
Taylor Holberton4e557192016-11-23 11:48:06 -0800701/** Get the number of enumerated items in the control.
702 * @param ctl An initialized control handle.
703 * @returns The number of enumerated items in the control.
704 * @ingroup libtinyalsa-mixer
705 */
Taylor Holbertoncac43a22016-12-01 18:11:24 -0800706unsigned int mixer_ctl_get_num_enums(const struct mixer_ctl *ctl)
Simon Wilson066c9f62011-06-05 18:23:05 -0700707{
Simon Wilson193b1c32011-06-07 23:42:38 -0700708 if (!ctl)
Simon Wilson066c9f62011-06-05 18:23:05 -0700709 return 0;
Simon Wilson066c9f62011-06-05 18:23:05 -0700710
Richard Fitzgerald899cece2014-09-09 17:03:21 +0100711 return ctl->info.value.enumerated.items;
Simon Wilson066c9f62011-06-05 18:23:05 -0700712}
713
David.Coutherut9b423962013-06-03 13:45:51 +0200714int mixer_ctl_fill_enum_string(struct mixer_ctl *ctl)
715{
716 struct snd_ctl_elem_info tmp;
717 unsigned int m;
718 char **enames;
719
720 if (ctl->ename) {
721 return 0;
722 }
723
Taylor Holberton6a38d5f2016-10-03 21:07:39 -0400724 enames = calloc(ctl->info.value.enumerated.items, sizeof(char*));
David.Coutherut9b423962013-06-03 13:45:51 +0200725 if (!enames)
726 goto fail;
Taylor Holberton6a38d5f2016-10-03 21:07:39 -0400727 for (m = 0; m < ctl->info.value.enumerated.items; m++) {
David.Coutherut9b423962013-06-03 13:45:51 +0200728 memset(&tmp, 0, sizeof(tmp));
Taylor Holberton6a38d5f2016-10-03 21:07:39 -0400729 tmp.id.numid = ctl->info.id.numid;
David.Coutherut9b423962013-06-03 13:45:51 +0200730 tmp.value.enumerated.item = m;
731 if (ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_INFO, &tmp) < 0)
732 goto fail;
733 enames[m] = strdup(tmp.value.enumerated.name);
734 if (!enames[m])
735 goto fail;
736 }
737 ctl->ename = enames;
738 return 0;
739
740fail:
741 if (enames) {
Taylor Holberton6a38d5f2016-10-03 21:07:39 -0400742 for (m = 0; m < ctl->info.value.enumerated.items; m++) {
David.Coutherut9b423962013-06-03 13:45:51 +0200743 if (enames[m]) {
744 free(enames[m]);
745 }
746 }
747 free(enames);
748 }
749 return -1;
750}
751
Taylor Holberton4e557192016-11-23 11:48:06 -0800752/** Gets the string representation of an enumerated item.
753 * @param ctl An initialized control handle.
754 * @param enum_id The index of the enumerated value.
755 * @returns A string representation of the enumerated item.
756 * @ingroup libtinyalsa-mixer
757 */
Simon Wilsonb29ac1a2012-03-08 10:15:08 -0800758const char *mixer_ctl_get_enum_string(struct mixer_ctl *ctl,
759 unsigned int enum_id)
Simon Wilson79d39652011-05-25 13:44:23 -0700760{
Richard Fitzgerald899cece2014-09-09 17:03:21 +0100761 if (!ctl || (ctl->info.type != SNDRV_CTL_ELEM_TYPE_ENUMERATED) ||
Taylor Holberton6a38d5f2016-10-03 21:07:39 -0400762 (enum_id >= ctl->info.value.enumerated.items) ||
David.Coutherut9b423962013-06-03 13:45:51 +0200763 mixer_ctl_fill_enum_string(ctl) != 0)
Simon Wilsonb29ac1a2012-03-08 10:15:08 -0800764 return NULL;
Simon Wilson79d39652011-05-25 13:44:23 -0700765
Simon Wilsonb29ac1a2012-03-08 10:15:08 -0800766 return (const char *)ctl->ename[enum_id];
Simon Wilson79d39652011-05-25 13:44:23 -0700767}
768
Taylor Holberton4e557192016-11-23 11:48:06 -0800769/** Set an enumeration value by string value.
770 * @param ctl An enumerated mixer control.
771 * @param string The string representation of an enumeration.
772 * @returns On success, zero.
773 * On failure, zero.
774 * @ingroup libtinyalsa-mixer
775 */
Simon Wilsonf0a20ee2011-06-05 21:18:52 -0700776int mixer_ctl_set_enum_by_string(struct mixer_ctl *ctl, const char *string)
777{
778 unsigned int i, num_enums;
779 struct snd_ctl_elem_value ev;
Simon Wilson193b1c32011-06-07 23:42:38 -0700780 int ret;
Simon Wilsonf0a20ee2011-06-05 21:18:52 -0700781
Taylor Holberton6a38d5f2016-10-03 21:07:39 -0400782 if (!ctl || (ctl->info.type != SNDRV_CTL_ELEM_TYPE_ENUMERATED) ||
David.Coutherut9b423962013-06-03 13:45:51 +0200783 mixer_ctl_fill_enum_string(ctl) != 0)
Simon Wilson193b1c32011-06-07 23:42:38 -0700784 return -EINVAL;
Simon Wilsonf0a20ee2011-06-05 21:18:52 -0700785
Richard Fitzgerald899cece2014-09-09 17:03:21 +0100786 num_enums = ctl->info.value.enumerated.items;
Simon Wilsonf0a20ee2011-06-05 21:18:52 -0700787 for (i = 0; i < num_enums; i++) {
788 if (!strcmp(string, ctl->ename[i])) {
789 memset(&ev, 0, sizeof(ev));
790 ev.value.enumerated.item[0] = i;
Richard Fitzgerald899cece2014-09-09 17:03:21 +0100791 ev.id.numid = ctl->info.id.numid;
Simon Wilson193b1c32011-06-07 23:42:38 -0700792 ret = ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_WRITE, &ev);
793 if (ret < 0)
794 return ret;
Simon Wilsonf0a20ee2011-06-05 21:18:52 -0700795 return 0;
796 }
797 }
798
Simon Wilson193b1c32011-06-07 23:42:38 -0700799 return -EINVAL;
Simon Wilsonf0a20ee2011-06-05 21:18:52 -0700800}
801