Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 1 | /* 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 Zhang | 7ed2ffb | 2016-04-22 17:59:40 -0700 | [diff] [blame] | 31 | #include <stdint.h> |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 32 | #include <string.h> |
| 33 | #include <unistd.h> |
| 34 | #include <fcntl.h> |
| 35 | #include <errno.h> |
| 36 | #include <ctype.h> |
Richard Fitzgerald | 57a8774 | 2014-09-09 16:54:12 +0100 | [diff] [blame] | 37 | #include <limits.h> |
Dima Krasner | 696c448 | 2016-03-05 19:50:02 +0200 | [diff] [blame] | 38 | #include <time.h> |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 39 | |
Simon Wilson | 6a52f2c | 2012-05-04 16:32:10 -0700 | [diff] [blame] | 40 | #include <sys/ioctl.h> |
| 41 | |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 42 | #include <linux/ioctl.h> |
| 43 | #define __force |
| 44 | #define __bitwise |
| 45 | #define __user |
| 46 | #include <sound/asound.h> |
| 47 | |
Ricardo Biehl Pasquali | 04952ee | 2016-10-05 20:32:09 -0300 | [diff] [blame] | 48 | #include <tinyalsa/mixer.h> |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 49 | |
Taylor Holberton | 7c8b20a | 2016-10-01 19:25:19 -0400 | [diff] [blame] | 50 | /** A mixer control. |
Taylor Holberton | 8ae5d11 | 2016-11-19 10:35:25 -0800 | [diff] [blame] | 51 | * @ingroup libtinyalsa-mixer |
Taylor Holberton | 7c8b20a | 2016-10-01 19:25:19 -0400 | [diff] [blame] | 52 | */ |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 53 | struct mixer_ctl { |
Taylor Holberton | 7c8b20a | 2016-10-01 19:25:19 -0400 | [diff] [blame] | 54 | /** The mixer that the mixer control belongs to */ |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 55 | struct mixer *mixer; |
Taylor Holberton | ad4d7d7 | 2016-11-23 13:34:18 -0800 | [diff] [blame] | 56 | /** Information on the control's value (i.e. type, number of values) */ |
Richard Fitzgerald | 899cece | 2014-09-09 17:03:21 +0100 | [diff] [blame] | 57 | struct snd_ctl_elem_info info; |
Taylor Holberton | ad4d7d7 | 2016-11-23 13:34:18 -0800 | [diff] [blame] | 58 | /** A list of string representations of enumerated values (only valid for enumerated controls) */ |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 59 | char **ename; |
| 60 | }; |
| 61 | |
Taylor Holberton | 7c8b20a | 2016-10-01 19:25:19 -0400 | [diff] [blame] | 62 | /** A mixer handle. |
Taylor Holberton | 8ae5d11 | 2016-11-19 10:35:25 -0800 | [diff] [blame] | 63 | * @ingroup libtinyalsa-mixer |
Taylor Holberton | 7c8b20a | 2016-10-01 19:25:19 -0400 | [diff] [blame] | 64 | */ |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 65 | struct mixer { |
Taylor Holberton | 7c8b20a | 2016-10-01 19:25:19 -0400 | [diff] [blame] | 66 | /** File descriptor for the card */ |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 67 | int fd; |
Taylor Holberton | 7c8b20a | 2016-10-01 19:25:19 -0400 | [diff] [blame] | 68 | /** Card information */ |
Simon Wilson | ec28139 | 2013-06-28 16:21:31 -0700 | [diff] [blame] | 69 | struct snd_ctl_card_info card_info; |
Taylor Holberton | 7c8b20a | 2016-10-01 19:25:19 -0400 | [diff] [blame] | 70 | /** A continuous array of mixer controls */ |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 71 | struct mixer_ctl *ctl; |
Taylor Holberton | 7c8b20a | 2016-10-01 19:25:19 -0400 | [diff] [blame] | 72 | /** The number of mixer controls */ |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 73 | unsigned int count; |
| 74 | }; |
| 75 | |
Richard Fitzgerald | fd32903 | 2014-09-09 17:14:09 +0100 | [diff] [blame^] | 76 | static void mixer_cleanup_control(struct mixer_ctl *ctl) |
| 77 | { |
| 78 | unsigned int m; |
| 79 | |
| 80 | if (ctl->ename) { |
| 81 | unsigned int max = ctl->info.value.enumerated.items; |
| 82 | for (m = 0; m < max; m++) |
| 83 | free(ctl->ename[m]); |
| 84 | free(ctl->ename); |
| 85 | } |
| 86 | } |
| 87 | |
Taylor Holberton | 7c8b20a | 2016-10-01 19:25:19 -0400 | [diff] [blame] | 88 | /** Closes a mixer returned by @ref mixer_open. |
| 89 | * @param mixer A mixer handle. |
Taylor Holberton | 8ae5d11 | 2016-11-19 10:35:25 -0800 | [diff] [blame] | 90 | * @ingroup libtinyalsa-mixer |
Taylor Holberton | 7c8b20a | 2016-10-01 19:25:19 -0400 | [diff] [blame] | 91 | */ |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 92 | void mixer_close(struct mixer *mixer) |
| 93 | { |
Richard Fitzgerald | fd32903 | 2014-09-09 17:14:09 +0100 | [diff] [blame^] | 94 | unsigned int n; |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 95 | |
Simon Wilson | 193b1c3 | 2011-06-07 23:42:38 -0700 | [diff] [blame] | 96 | if (!mixer) |
Simon Wilson | d2cb503 | 2011-06-04 00:57:17 -0700 | [diff] [blame] | 97 | return; |
Simon Wilson | d2cb503 | 2011-06-04 00:57:17 -0700 | [diff] [blame] | 98 | |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 99 | if (mixer->fd >= 0) |
| 100 | close(mixer->fd); |
| 101 | |
| 102 | if (mixer->ctl) { |
Richard Fitzgerald | fd32903 | 2014-09-09 17:14:09 +0100 | [diff] [blame^] | 103 | for (n = 0; n < mixer->count; n++) |
| 104 | mixer_cleanup_control(&mixer->ctl[n]); |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 105 | free(mixer->ctl); |
| 106 | } |
| 107 | |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 108 | free(mixer); |
| 109 | |
| 110 | /* TODO: verify frees */ |
| 111 | } |
| 112 | |
Richard Fitzgerald | fd32903 | 2014-09-09 17:14:09 +0100 | [diff] [blame^] | 113 | static void *mixer_realloc_z(void *ptr, size_t curnum, size_t newnum, size_t size) |
| 114 | { |
| 115 | int8_t *newp; |
| 116 | |
| 117 | newp = realloc(ptr, size * newnum); |
| 118 | if (!newp) |
| 119 | return NULL; |
| 120 | |
| 121 | memset(newp + (curnum * size), 0, (newnum - curnum) * size); |
| 122 | return newp; |
| 123 | } |
| 124 | |
| 125 | static int add_controls(struct mixer *mixer) |
| 126 | { |
| 127 | struct snd_ctl_elem_list elist; |
| 128 | struct snd_ctl_elem_id *eid = NULL; |
| 129 | struct mixer_ctl *ctl; |
| 130 | int fd = mixer->fd; |
| 131 | const unsigned int old_count = mixer->count; |
| 132 | unsigned int new_count; |
| 133 | unsigned int n; |
| 134 | |
| 135 | memset(&elist, 0, sizeof(elist)); |
| 136 | if (ioctl(fd, SNDRV_CTL_IOCTL_ELEM_LIST, &elist) < 0) |
| 137 | goto fail; |
| 138 | |
| 139 | if (old_count == elist.count) |
| 140 | return 0; /* no new controls return unchanged */ |
| 141 | |
| 142 | if (old_count > elist.count) |
| 143 | return -1; /* driver has removed controls - this is bad */ |
| 144 | |
| 145 | ctl = mixer_realloc_z(mixer->ctl, old_count, elist.count, |
| 146 | sizeof(struct mixer_ctl)); |
| 147 | if (!ctl) |
| 148 | goto fail; |
| 149 | |
| 150 | mixer->ctl = ctl; |
| 151 | |
| 152 | /* ALSA drivers are not supposed to remove or re-order controls that |
| 153 | * have already been created so we know that any new controls must |
| 154 | * be after the ones we have already collected |
| 155 | */ |
| 156 | new_count = elist.count; |
| 157 | elist.space = new_count - old_count; /* controls we haven't seen before */ |
| 158 | elist.offset = old_count; /* first control we haven't seen */ |
| 159 | |
| 160 | eid = calloc(elist.space, sizeof(struct snd_ctl_elem_id)); |
| 161 | if (!eid) |
| 162 | goto fail; |
| 163 | |
| 164 | elist.pids = eid; |
| 165 | |
| 166 | if (ioctl(fd, SNDRV_CTL_IOCTL_ELEM_LIST, &elist) < 0) |
| 167 | goto fail; |
| 168 | |
| 169 | for (n = old_count; n < new_count; n++) { |
| 170 | struct snd_ctl_elem_info *ei = &mixer->ctl[n].info; |
| 171 | ei->id.numid = eid[n - old_count].numid; |
| 172 | if (ioctl(fd, SNDRV_CTL_IOCTL_ELEM_INFO, ei) < 0) |
| 173 | goto fail_extend; |
| 174 | ctl[n].mixer = mixer; |
| 175 | } |
| 176 | |
| 177 | mixer->count = new_count; |
| 178 | free(eid); |
| 179 | return 0; |
| 180 | |
| 181 | fail_extend: |
| 182 | /* cleanup the control we failed on but leave the ones that were already |
| 183 | * added. Also no advantage to shrinking the resized memory block, we |
| 184 | * might want to extend the controls again later |
| 185 | */ |
| 186 | mixer_cleanup_control(&ctl[n]); |
| 187 | |
| 188 | mixer->count = n; /* keep controls we successfully added */ |
| 189 | /* fall through... */ |
| 190 | fail: |
| 191 | free(eid); |
| 192 | return -1; |
| 193 | } |
| 194 | |
Taylor Holberton | 7c8b20a | 2016-10-01 19:25:19 -0400 | [diff] [blame] | 195 | /** Opens a mixer for a given card. |
| 196 | * @param card The card to open the mixer for. |
Taylor Holberton | b7a2857 | 2016-11-19 23:45:00 -0500 | [diff] [blame] | 197 | * @returns An initialized mixer handle. |
Taylor Holberton | 8ae5d11 | 2016-11-19 10:35:25 -0800 | [diff] [blame] | 198 | * @ingroup libtinyalsa-mixer |
Taylor Holberton | 7c8b20a | 2016-10-01 19:25:19 -0400 | [diff] [blame] | 199 | */ |
Simon Wilson | 1bd580f | 2011-06-02 15:58:41 -0700 | [diff] [blame] | 200 | struct mixer *mixer_open(unsigned int card) |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 201 | { |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 202 | struct mixer *mixer = NULL; |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 203 | int fd; |
Simon Wilson | 1bd580f | 2011-06-02 15:58:41 -0700 | [diff] [blame] | 204 | char fn[256]; |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 205 | |
Simon Wilson | 1bd580f | 2011-06-02 15:58:41 -0700 | [diff] [blame] | 206 | snprintf(fn, sizeof(fn), "/dev/snd/controlC%u", card); |
| 207 | fd = open(fn, O_RDWR); |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 208 | if (fd < 0) |
| 209 | return 0; |
| 210 | |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 211 | mixer = calloc(1, sizeof(*mixer)); |
| 212 | if (!mixer) |
| 213 | goto fail; |
| 214 | |
Simon Wilson | ec28139 | 2013-06-28 16:21:31 -0700 | [diff] [blame] | 215 | if (ioctl(fd, SNDRV_CTL_IOCTL_CARD_INFO, &mixer->card_info) < 0) |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 216 | goto fail; |
| 217 | |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 218 | mixer->fd = fd; |
Richard Fitzgerald | fd32903 | 2014-09-09 17:14:09 +0100 | [diff] [blame^] | 219 | |
| 220 | if (add_controls(mixer) != 0) |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 221 | goto fail; |
| 222 | |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 223 | return mixer; |
| 224 | |
| 225 | fail: |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 226 | if (mixer) |
| 227 | mixer_close(mixer); |
| 228 | else if (fd >= 0) |
| 229 | close(fd); |
Richard Fitzgerald | fd32903 | 2014-09-09 17:14:09 +0100 | [diff] [blame^] | 230 | return NULL; |
| 231 | } |
| 232 | |
| 233 | /** Some controls may not be present at boot time, e.g. controls from runtime |
| 234 | * loadable DSP firmware. This function adds any new controls that have appeared |
| 235 | * since mixer_open() or the last call to this function. This assumes a well- |
| 236 | * behaved codec driver that does not delete controls that already exists, so |
| 237 | * any added controls must be after the last one we already saw. Scanning only |
| 238 | * the new controls is much faster than calling mixer_close() then mixer_open() |
| 239 | * to re-scan all controls. |
| 240 | * |
| 241 | * NOTE: this invalidates any struct mixer_ctl pointers previously obtained |
| 242 | * from mixer_get_ctl() and mixer_get_ctl_by_name(). Either refresh all your |
| 243 | * stored pointers after calling mixer_update_ctls(), or (better) do not |
| 244 | * store struct mixer_ctl pointers, instead lookup the control by name or |
| 245 | * id only when you are about to use it. The overhead of lookup by id |
| 246 | * using mixer_get_ctl() is negligible. |
| 247 | * @param mixer An initialized mixer handle. |
| 248 | * @returns 0 on success, -1 on failure |
| 249 | */ |
| 250 | int mixer_add_new_ctls(struct mixer *mixer) |
| 251 | { |
| 252 | if (!mixer) |
| 253 | return 0; |
| 254 | |
| 255 | return add_controls(mixer); |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Taylor Holberton | b7a2857 | 2016-11-19 23:45:00 -0500 | [diff] [blame] | 258 | /** Gets the name of the mixer's card. |
| 259 | * @param mixer An initialized mixer handle. |
| 260 | * @returns The name of the mixer's card. |
| 261 | * @ingroup libtinyalsa-mixer |
| 262 | */ |
Taylor Holberton | cac43a2 | 2016-12-01 18:11:24 -0800 | [diff] [blame] | 263 | const char *mixer_get_name(const struct mixer *mixer) |
Simon Wilson | ec28139 | 2013-06-28 16:21:31 -0700 | [diff] [blame] | 264 | { |
| 265 | return (const char *)mixer->card_info.name; |
| 266 | } |
| 267 | |
Taylor Holberton | b7a2857 | 2016-11-19 23:45:00 -0500 | [diff] [blame] | 268 | /** Gets the number of mixer controls for a given mixer. |
| 269 | * @param mixer An initialized mixer handle. |
| 270 | * @returns The number of mixer controls for the given mixer. |
| 271 | * @ingroup libtinyalsa-mixer |
| 272 | */ |
Taylor Holberton | cac43a2 | 2016-12-01 18:11:24 -0800 | [diff] [blame] | 273 | unsigned int mixer_get_num_ctls(const struct mixer *mixer) |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 274 | { |
Simon Wilson | 193b1c3 | 2011-06-07 23:42:38 -0700 | [diff] [blame] | 275 | if (!mixer) |
Simon Wilson | 98c1f16 | 2011-06-07 16:12:32 -0700 | [diff] [blame] | 276 | return 0; |
Simon Wilson | d2cb503 | 2011-06-04 00:57:17 -0700 | [diff] [blame] | 277 | |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 278 | return mixer->count; |
| 279 | } |
| 280 | |
Taylor Holberton | 94c7c83 | 2016-12-01 18:35:24 -0800 | [diff] [blame] | 281 | /** Gets the number of mixer controls, that go by a specified name, for a given mixer. |
| 282 | * @param mixer An initialized mixer handle. |
| 283 | * @param name The name of the mixer control |
| 284 | * @returns The number of mixer controls, specified by @p name, for the given mixer. |
| 285 | * @ingroup libtinyalsa-mixer |
| 286 | */ |
| 287 | unsigned int mixer_get_num_ctls_by_name(const struct mixer *mixer, const char *name) |
| 288 | { |
| 289 | unsigned int n; |
| 290 | unsigned int count = 0; |
| 291 | struct mixer_ctl *ctl; |
| 292 | |
| 293 | if (!mixer) |
| 294 | return 0; |
| 295 | |
| 296 | ctl = mixer->ctl; |
| 297 | |
| 298 | for (n = 0; n < mixer->count; n++) |
| 299 | if (!strcmp(name, (char*) ctl[n].info.id.name)) |
| 300 | count++; |
| 301 | |
| 302 | return count; |
| 303 | } |
| 304 | |
Taylor Holberton | b7a2857 | 2016-11-19 23:45:00 -0500 | [diff] [blame] | 305 | /** Gets a mixer control handle, by the mixer control's id. |
Taylor Holberton | a94295b | 2016-12-01 18:23:16 -0800 | [diff] [blame] | 306 | * For non-const access, see @ref mixer_get_ctl |
| 307 | * @param mixer An initialized mixer handle. |
| 308 | * @param id The control's id in the given mixer. |
| 309 | * @returns A handle to the mixer control. |
| 310 | * @ingroup libtinyalsa-mixer |
| 311 | */ |
| 312 | const struct mixer_ctl *mixer_get_ctl_const(const struct mixer *mixer, unsigned int id) |
| 313 | { |
| 314 | if (mixer && (id < mixer->count)) |
| 315 | return mixer->ctl + id; |
| 316 | |
| 317 | return NULL; |
| 318 | } |
| 319 | |
| 320 | /** Gets a mixer control handle, by the mixer control's id. |
| 321 | * For const access, see @ref mixer_get_ctl_const |
Taylor Holberton | b7a2857 | 2016-11-19 23:45:00 -0500 | [diff] [blame] | 322 | * @param mixer An initialized mixer handle. |
| 323 | * @param id The control's id in the given mixer. |
| 324 | * @returns A handle to the mixer control. |
| 325 | * @ingroup libtinyalsa-mixer |
| 326 | */ |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 327 | struct mixer_ctl *mixer_get_ctl(struct mixer *mixer, unsigned int id) |
| 328 | { |
Simon Wilson | 98c1f16 | 2011-06-07 16:12:32 -0700 | [diff] [blame] | 329 | if (mixer && (id < mixer->count)) |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 330 | return mixer->ctl + id; |
| 331 | |
| 332 | return NULL; |
| 333 | } |
| 334 | |
Taylor Holberton | b7a2857 | 2016-11-19 23:45:00 -0500 | [diff] [blame] | 335 | /** Gets the first instance of mixer control handle, by the mixer control's name. |
| 336 | * @param mixer An initialized mixer handle. |
| 337 | * @param name The control's name in the given mixer. |
| 338 | * @returns A handle to the mixer control. |
| 339 | * @ingroup libtinyalsa-mixer |
| 340 | */ |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 341 | struct mixer_ctl *mixer_get_ctl_by_name(struct mixer *mixer, const char *name) |
| 342 | { |
Frédéric Boisnard | 9e2c240 | 2013-09-17 22:43:18 +0200 | [diff] [blame] | 343 | return mixer_get_ctl_by_name_and_index(mixer, name, 0); |
| 344 | } |
| 345 | |
Taylor Holberton | b7a2857 | 2016-11-19 23:45:00 -0500 | [diff] [blame] | 346 | /** Gets an instance of mixer control handle, by the mixer control's name and index. |
| 347 | * For instance, if two controls have the name of 'Volume', then and index of 1 would return the second control. |
| 348 | * @param mixer An initialized mixer handle. |
| 349 | * @param name The control's name in the given mixer. |
| 350 | * @param index The control's index. |
| 351 | * @returns A handle to the mixer control. |
| 352 | * @ingroup libtinyalsa-mixer |
| 353 | */ |
Frédéric Boisnard | 9e2c240 | 2013-09-17 22:43:18 +0200 | [diff] [blame] | 354 | struct mixer_ctl *mixer_get_ctl_by_name_and_index(struct mixer *mixer, |
| 355 | const char *name, |
| 356 | unsigned int index) |
| 357 | { |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 358 | unsigned int n; |
Svyatoslav Mishyn | c732836 | 2016-01-24 19:43:38 +0200 | [diff] [blame] | 359 | struct mixer_ctl *ctl; |
Simon Wilson | d2cb503 | 2011-06-04 00:57:17 -0700 | [diff] [blame] | 360 | |
Simon Wilson | 98c1f16 | 2011-06-07 16:12:32 -0700 | [diff] [blame] | 361 | if (!mixer) |
Simon Wilson | 193b1c3 | 2011-06-07 23:42:38 -0700 | [diff] [blame] | 362 | return NULL; |
Simon Wilson | d2cb503 | 2011-06-04 00:57:17 -0700 | [diff] [blame] | 363 | |
Svyatoslav Mishyn | c732836 | 2016-01-24 19:43:38 +0200 | [diff] [blame] | 364 | ctl = mixer->ctl; |
| 365 | |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 366 | for (n = 0; n < mixer->count; n++) |
Richard Fitzgerald | 899cece | 2014-09-09 17:03:21 +0100 | [diff] [blame] | 367 | if (!strcmp(name, (char*) ctl[n].info.id.name)) |
Frédéric Boisnard | 9e2c240 | 2013-09-17 22:43:18 +0200 | [diff] [blame] | 368 | if (index-- == 0) |
| 369 | return mixer->ctl + n; |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 370 | |
| 371 | return NULL; |
| 372 | } |
| 373 | |
Taylor Holberton | b7a2857 | 2016-11-19 23:45:00 -0500 | [diff] [blame] | 374 | /** Updates the control's info. |
| 375 | * This is useful for a program that may be idle for a period of time. |
| 376 | * @param ctl An initialized control handle. |
| 377 | * @ingroup libtinyalsa-mixer |
| 378 | */ |
Simon Wilson | 710df88 | 2013-06-28 16:17:50 -0700 | [diff] [blame] | 379 | void mixer_ctl_update(struct mixer_ctl *ctl) |
| 380 | { |
| 381 | ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_INFO, ctl->info); |
| 382 | } |
| 383 | |
Taylor Holberton | b7a2857 | 2016-11-19 23:45:00 -0500 | [diff] [blame] | 384 | /** Gets the control's ID. |
| 385 | * @param ctl An initialized control handle. |
| 386 | * @returns On success, the control's ID is returned. |
| 387 | * On error, UINT_MAX is returned instead. |
| 388 | * @ingroup libtinyalsa-mixer |
| 389 | */ |
Taylor Holberton | cac43a2 | 2016-12-01 18:11:24 -0800 | [diff] [blame] | 390 | unsigned int mixer_ctl_get_id(const struct mixer_ctl *ctl) |
Richard Fitzgerald | 57a8774 | 2014-09-09 16:54:12 +0100 | [diff] [blame] | 391 | { |
| 392 | if (!ctl) |
| 393 | return UINT_MAX; |
| 394 | |
| 395 | /* numid values start at 1, return a 0-base value that |
| 396 | * can be passed to mixer_get_ctl() |
| 397 | */ |
Richard Fitzgerald | 899cece | 2014-09-09 17:03:21 +0100 | [diff] [blame] | 398 | return ctl->info.id.numid - 1; |
Richard Fitzgerald | 57a8774 | 2014-09-09 16:54:12 +0100 | [diff] [blame] | 399 | } |
| 400 | |
Taylor Holberton | b7a2857 | 2016-11-19 23:45:00 -0500 | [diff] [blame] | 401 | /** Gets the name of the control. |
| 402 | * @param ctl An initialized control handle. |
| 403 | * @returns On success, the name of the control. |
| 404 | * On error, NULL. |
| 405 | * @ingroup libtinyalsa-mixer |
| 406 | */ |
Taylor Holberton | cac43a2 | 2016-12-01 18:11:24 -0800 | [diff] [blame] | 407 | const char *mixer_ctl_get_name(const struct mixer_ctl *ctl) |
Simon Wilson | d2cb503 | 2011-06-04 00:57:17 -0700 | [diff] [blame] | 408 | { |
Simon Wilson | b29ac1a | 2012-03-08 10:15:08 -0800 | [diff] [blame] | 409 | if (!ctl) |
| 410 | return NULL; |
Simon Wilson | d2cb503 | 2011-06-04 00:57:17 -0700 | [diff] [blame] | 411 | |
Richard Fitzgerald | 899cece | 2014-09-09 17:03:21 +0100 | [diff] [blame] | 412 | return (const char *)ctl->info.id.name; |
Simon Wilson | d2cb503 | 2011-06-04 00:57:17 -0700 | [diff] [blame] | 413 | } |
| 414 | |
Taylor Holberton | b7a2857 | 2016-11-19 23:45:00 -0500 | [diff] [blame] | 415 | /** Gets the value type of the control. |
| 416 | * @param ctl An initialized control handle |
| 417 | * @returns On success, the type of mixer control. |
| 418 | * On failure, it returns @ref MIXER_CTL_TYPE_UNKNOWN |
| 419 | * @ingroup libtinyalsa-mixer |
| 420 | */ |
Taylor Holberton | cac43a2 | 2016-12-01 18:11:24 -0800 | [diff] [blame] | 421 | enum mixer_ctl_type mixer_ctl_get_type(const struct mixer_ctl *ctl) |
Simon Wilson | d2cb503 | 2011-06-04 00:57:17 -0700 | [diff] [blame] | 422 | { |
Simon Wilson | 193b1c3 | 2011-06-07 23:42:38 -0700 | [diff] [blame] | 423 | if (!ctl) |
Simon Wilson | d2cb503 | 2011-06-04 00:57:17 -0700 | [diff] [blame] | 424 | return MIXER_CTL_TYPE_UNKNOWN; |
Simon Wilson | d2cb503 | 2011-06-04 00:57:17 -0700 | [diff] [blame] | 425 | |
Richard Fitzgerald | 899cece | 2014-09-09 17:03:21 +0100 | [diff] [blame] | 426 | switch (ctl->info.type) { |
Simon Wilson | d2cb503 | 2011-06-04 00:57:17 -0700 | [diff] [blame] | 427 | case SNDRV_CTL_ELEM_TYPE_BOOLEAN: return MIXER_CTL_TYPE_BOOL; |
| 428 | case SNDRV_CTL_ELEM_TYPE_INTEGER: return MIXER_CTL_TYPE_INT; |
| 429 | case SNDRV_CTL_ELEM_TYPE_ENUMERATED: return MIXER_CTL_TYPE_ENUM; |
| 430 | case SNDRV_CTL_ELEM_TYPE_BYTES: return MIXER_CTL_TYPE_BYTE; |
| 431 | case SNDRV_CTL_ELEM_TYPE_IEC958: return MIXER_CTL_TYPE_IEC958; |
| 432 | case SNDRV_CTL_ELEM_TYPE_INTEGER64: return MIXER_CTL_TYPE_INT64; |
| 433 | default: return MIXER_CTL_TYPE_UNKNOWN; |
| 434 | }; |
| 435 | } |
| 436 | |
Taylor Holberton | b7a2857 | 2016-11-19 23:45:00 -0500 | [diff] [blame] | 437 | /** Gets the string that describes the value type of the control. |
| 438 | * @param ctl An initialized control handle |
| 439 | * @returns On success, a string describing type of mixer control. |
| 440 | * @ingroup libtinyalsa-mixer |
| 441 | */ |
Taylor Holberton | cac43a2 | 2016-12-01 18:11:24 -0800 | [diff] [blame] | 442 | const char *mixer_ctl_get_type_string(const struct mixer_ctl *ctl) |
Simon Wilson | d2cb503 | 2011-06-04 00:57:17 -0700 | [diff] [blame] | 443 | { |
Simon Wilson | 193b1c3 | 2011-06-07 23:42:38 -0700 | [diff] [blame] | 444 | if (!ctl) |
Simon Wilson | d2cb503 | 2011-06-04 00:57:17 -0700 | [diff] [blame] | 445 | return ""; |
Simon Wilson | d2cb503 | 2011-06-04 00:57:17 -0700 | [diff] [blame] | 446 | |
Richard Fitzgerald | 899cece | 2014-09-09 17:03:21 +0100 | [diff] [blame] | 447 | switch (ctl->info.type) { |
Simon Wilson | d2cb503 | 2011-06-04 00:57:17 -0700 | [diff] [blame] | 448 | case SNDRV_CTL_ELEM_TYPE_BOOLEAN: return "BOOL"; |
| 449 | case SNDRV_CTL_ELEM_TYPE_INTEGER: return "INT"; |
| 450 | case SNDRV_CTL_ELEM_TYPE_ENUMERATED: return "ENUM"; |
| 451 | case SNDRV_CTL_ELEM_TYPE_BYTES: return "BYTE"; |
| 452 | case SNDRV_CTL_ELEM_TYPE_IEC958: return "IEC958"; |
| 453 | case SNDRV_CTL_ELEM_TYPE_INTEGER64: return "INT64"; |
| 454 | default: return "Unknown"; |
| 455 | }; |
| 456 | } |
| 457 | |
Taylor Holberton | b7a2857 | 2016-11-19 23:45:00 -0500 | [diff] [blame] | 458 | /** Gets the number of values in the control. |
| 459 | * @param ctl An initialized control handle |
| 460 | * @returns The number of values in the mixer control |
| 461 | * @ingroup libtinyalsa-mixer |
| 462 | */ |
Taylor Holberton | cac43a2 | 2016-12-01 18:11:24 -0800 | [diff] [blame] | 463 | unsigned int mixer_ctl_get_num_values(const struct mixer_ctl *ctl) |
Simon Wilson | d2cb503 | 2011-06-04 00:57:17 -0700 | [diff] [blame] | 464 | { |
Simon Wilson | 193b1c3 | 2011-06-07 23:42:38 -0700 | [diff] [blame] | 465 | if (!ctl) |
Simon Wilson | d2cb503 | 2011-06-04 00:57:17 -0700 | [diff] [blame] | 466 | return 0; |
Simon Wilson | d2cb503 | 2011-06-04 00:57:17 -0700 | [diff] [blame] | 467 | |
Richard Fitzgerald | 899cece | 2014-09-09 17:03:21 +0100 | [diff] [blame] | 468 | return ctl->info.count; |
Simon Wilson | d2cb503 | 2011-06-04 00:57:17 -0700 | [diff] [blame] | 469 | } |
| 470 | |
Taylor Holberton | cac43a2 | 2016-12-01 18:11:24 -0800 | [diff] [blame] | 471 | static int percent_to_int(const struct snd_ctl_elem_info *ei, int percent) |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 472 | { |
Baptiste Robert | 4a484e1 | 2013-09-12 15:37:53 +0200 | [diff] [blame] | 473 | if ((percent > 100) || (percent < 0)) { |
| 474 | return -EINVAL; |
| 475 | } |
Simon Wilson | 98c1f16 | 2011-06-07 16:12:32 -0700 | [diff] [blame] | 476 | |
Baptiste Robert | 4a484e1 | 2013-09-12 15:37:53 +0200 | [diff] [blame] | 477 | int range = (ei->value.integer.max - ei->value.integer.min); |
Simon Wilson | 98c1f16 | 2011-06-07 16:12:32 -0700 | [diff] [blame] | 478 | |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 479 | return ei->value.integer.min + (range * percent) / 100; |
| 480 | } |
| 481 | |
Taylor Holberton | cac43a2 | 2016-12-01 18:11:24 -0800 | [diff] [blame] | 482 | static int int_to_percent(const struct snd_ctl_elem_info *ei, int value) |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 483 | { |
| 484 | int range = (ei->value.integer.max - ei->value.integer.min); |
Simon Wilson | 98c1f16 | 2011-06-07 16:12:32 -0700 | [diff] [blame] | 485 | |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 486 | if (range == 0) |
| 487 | return 0; |
Simon Wilson | 98c1f16 | 2011-06-07 16:12:32 -0700 | [diff] [blame] | 488 | |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 489 | return ((value - ei->value.integer.min) / range) * 100; |
| 490 | } |
| 491 | |
Taylor Holberton | 4e55719 | 2016-11-23 11:48:06 -0800 | [diff] [blame] | 492 | /** Gets a percentage representation of a specified control value. |
| 493 | * @param ctl An initialized control handle. |
| 494 | * @param id The index of the value within the control. |
| 495 | * @returns On success, the percentage representation of the control value. |
| 496 | * On failure, -EINVAL is returned. |
| 497 | * @ingroup libtinyalsa-mixer |
| 498 | */ |
Taylor Holberton | cac43a2 | 2016-12-01 18:11:24 -0800 | [diff] [blame] | 499 | int mixer_ctl_get_percent(const struct mixer_ctl *ctl, unsigned int id) |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 500 | { |
Richard Fitzgerald | 899cece | 2014-09-09 17:03:21 +0100 | [diff] [blame] | 501 | if (!ctl || (ctl->info.type != SNDRV_CTL_ELEM_TYPE_INTEGER)) |
Simon Wilson | 193b1c3 | 2011-06-07 23:42:38 -0700 | [diff] [blame] | 502 | return -EINVAL; |
Simon Wilson | a1bb1e0 | 2011-05-26 18:22:00 -0700 | [diff] [blame] | 503 | |
Richard Fitzgerald | 899cece | 2014-09-09 17:03:21 +0100 | [diff] [blame] | 504 | return int_to_percent(&ctl->info, mixer_ctl_get_value(ctl, id)); |
Simon Wilson | a1bb1e0 | 2011-05-26 18:22:00 -0700 | [diff] [blame] | 505 | } |
| 506 | |
Taylor Holberton | 4e55719 | 2016-11-23 11:48:06 -0800 | [diff] [blame] | 507 | /** Sets the value of a control by percent, specified by the value index. |
| 508 | * @param ctl An initialized control handle. |
| 509 | * @param id The index of the value to set |
| 510 | * @param percent A percentage value between 0 and 100. |
| 511 | * @returns On success, zero is returned. |
| 512 | * On failure, non-zero is returned. |
| 513 | * @ingroup libtinyalsa-mixer |
| 514 | */ |
Simon Wilson | d2cb503 | 2011-06-04 00:57:17 -0700 | [diff] [blame] | 515 | int mixer_ctl_set_percent(struct mixer_ctl *ctl, unsigned int id, int percent) |
Simon Wilson | a1bb1e0 | 2011-05-26 18:22:00 -0700 | [diff] [blame] | 516 | { |
Richard Fitzgerald | 899cece | 2014-09-09 17:03:21 +0100 | [diff] [blame] | 517 | if (!ctl || (ctl->info.type != SNDRV_CTL_ELEM_TYPE_INTEGER)) |
Simon Wilson | 193b1c3 | 2011-06-07 23:42:38 -0700 | [diff] [blame] | 518 | return -EINVAL; |
Simon Wilson | a1bb1e0 | 2011-05-26 18:22:00 -0700 | [diff] [blame] | 519 | |
Richard Fitzgerald | 899cece | 2014-09-09 17:03:21 +0100 | [diff] [blame] | 520 | return mixer_ctl_set_value(ctl, id, percent_to_int(&ctl->info, percent)); |
Simon Wilson | a1bb1e0 | 2011-05-26 18:22:00 -0700 | [diff] [blame] | 521 | } |
| 522 | |
Taylor Holberton | 4e55719 | 2016-11-23 11:48:06 -0800 | [diff] [blame] | 523 | /** Gets the value of a control. |
| 524 | * @param ctl An initialized control handle. |
| 525 | * @param id The index of the control value. |
| 526 | * @returns On success, the specified value is returned. |
| 527 | * On failure, -EINVAL is returned. |
| 528 | * @ingroup libtinyalsa-mixer |
| 529 | */ |
Taylor Holberton | cac43a2 | 2016-12-01 18:11:24 -0800 | [diff] [blame] | 530 | int mixer_ctl_get_value(const struct mixer_ctl *ctl, unsigned int id) |
Simon Wilson | a1bb1e0 | 2011-05-26 18:22:00 -0700 | [diff] [blame] | 531 | { |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 532 | struct snd_ctl_elem_value ev; |
Simon Wilson | 193b1c3 | 2011-06-07 23:42:38 -0700 | [diff] [blame] | 533 | int ret; |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 534 | |
Richard Fitzgerald | 899cece | 2014-09-09 17:03:21 +0100 | [diff] [blame] | 535 | if (!ctl || (id >= ctl->info.count)) |
Simon Wilson | 193b1c3 | 2011-06-07 23:42:38 -0700 | [diff] [blame] | 536 | return -EINVAL; |
Simon Wilson | d2cb503 | 2011-06-04 00:57:17 -0700 | [diff] [blame] | 537 | |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 538 | memset(&ev, 0, sizeof(ev)); |
Richard Fitzgerald | 899cece | 2014-09-09 17:03:21 +0100 | [diff] [blame] | 539 | ev.id.numid = ctl->info.id.numid; |
Simon Wilson | 193b1c3 | 2011-06-07 23:42:38 -0700 | [diff] [blame] | 540 | ret = ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_READ, &ev); |
| 541 | if (ret < 0) |
| 542 | return ret; |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 543 | |
Richard Fitzgerald | 899cece | 2014-09-09 17:03:21 +0100 | [diff] [blame] | 544 | switch (ctl->info.type) { |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 545 | case SNDRV_CTL_ELEM_TYPE_BOOLEAN: |
Simon Wilson | d2cb503 | 2011-06-04 00:57:17 -0700 | [diff] [blame] | 546 | return !!ev.value.integer.value[id]; |
Simon Wilson | a1bb1e0 | 2011-05-26 18:22:00 -0700 | [diff] [blame] | 547 | |
| 548 | case SNDRV_CTL_ELEM_TYPE_INTEGER: |
Simon Wilson | d2cb503 | 2011-06-04 00:57:17 -0700 | [diff] [blame] | 549 | return ev.value.integer.value[id]; |
Simon Wilson | 066c9f6 | 2011-06-05 18:23:05 -0700 | [diff] [blame] | 550 | |
| 551 | case SNDRV_CTL_ELEM_TYPE_ENUMERATED: |
| 552 | return ev.value.enumerated.item[id]; |
Simon Wilson | a1bb1e0 | 2011-05-26 18:22:00 -0700 | [diff] [blame] | 553 | |
Pierre-Louis Bossart | 5251016 | 2011-10-24 15:00:17 -0500 | [diff] [blame] | 554 | case SNDRV_CTL_ELEM_TYPE_BYTES: |
| 555 | return ev.value.bytes.data[id]; |
| 556 | |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 557 | default: |
Simon Wilson | 193b1c3 | 2011-06-07 23:42:38 -0700 | [diff] [blame] | 558 | return -EINVAL; |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | return 0; |
| 562 | } |
| 563 | |
Taylor Holberton | 4e55719 | 2016-11-23 11:48:06 -0800 | [diff] [blame] | 564 | /** Gets the contents of a control's value array. |
| 565 | * @param ctl An initialized control handle. |
| 566 | * @param array A pointer to write the array data to. |
| 567 | * The size of this array must be equal to the number of items in the array |
| 568 | * multiplied by the size of each item. |
| 569 | * @param count The number of items in the array. |
| 570 | * This parameter must match the number of items in the control. |
| 571 | * The number of items in the control may be accessed via @ref mixer_ctl_get_num_values |
| 572 | * @returns On success, zero. |
| 573 | * On failure, non-zero. |
| 574 | * @ingroup libtinyalsa-mixer |
| 575 | */ |
Taylor Holberton | cac43a2 | 2016-12-01 18:11:24 -0800 | [diff] [blame] | 576 | int mixer_ctl_get_array(const struct mixer_ctl *ctl, void *array, size_t count) |
Dimitris Papastamos | f51c05b | 2012-05-28 13:40:33 +0100 | [diff] [blame] | 577 | { |
| 578 | struct snd_ctl_elem_value ev; |
Mythri P K | 45b2d04 | 2014-08-18 15:39:36 +0530 | [diff] [blame] | 579 | int ret = 0; |
Simon Wilson | 38f87f3 | 2012-10-23 15:05:23 -0700 | [diff] [blame] | 580 | size_t size; |
| 581 | void *source; |
Dimitris Papastamos | f51c05b | 2012-05-28 13:40:33 +0100 | [diff] [blame] | 582 | |
Richard Fitzgerald | 899cece | 2014-09-09 17:03:21 +0100 | [diff] [blame] | 583 | if (!ctl || (count > ctl->info.count) || !count || !array) |
Dimitris Papastamos | f51c05b | 2012-05-28 13:40:33 +0100 | [diff] [blame] | 584 | return -EINVAL; |
| 585 | |
| 586 | memset(&ev, 0, sizeof(ev)); |
Richard Fitzgerald | 899cece | 2014-09-09 17:03:21 +0100 | [diff] [blame] | 587 | ev.id.numid = ctl->info.id.numid; |
Dimitris Papastamos | f51c05b | 2012-05-28 13:40:33 +0100 | [diff] [blame] | 588 | |
Richard Fitzgerald | 899cece | 2014-09-09 17:03:21 +0100 | [diff] [blame] | 589 | switch (ctl->info.type) { |
Simon Wilson | 38f87f3 | 2012-10-23 15:05:23 -0700 | [diff] [blame] | 590 | case SNDRV_CTL_ELEM_TYPE_BOOLEAN: |
| 591 | case SNDRV_CTL_ELEM_TYPE_INTEGER: |
Mythri P K | 45b2d04 | 2014-08-18 15:39:36 +0530 | [diff] [blame] | 592 | ret = ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_READ, &ev); |
| 593 | if (ret < 0) |
| 594 | return ret; |
Simon Wilson | 38f87f3 | 2012-10-23 15:05:23 -0700 | [diff] [blame] | 595 | size = sizeof(ev.value.integer.value[0]); |
| 596 | source = ev.value.integer.value; |
| 597 | break; |
| 598 | |
| 599 | case SNDRV_CTL_ELEM_TYPE_BYTES: |
Mythri P K | 45b2d04 | 2014-08-18 15:39:36 +0530 | [diff] [blame] | 600 | /* check if this is new bytes TLV */ |
Richard Fitzgerald | 899cece | 2014-09-09 17:03:21 +0100 | [diff] [blame] | 601 | if (ctl->info.access & SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE) { |
Mythri P K | 45b2d04 | 2014-08-18 15:39:36 +0530 | [diff] [blame] | 602 | struct snd_ctl_tlv *tlv; |
| 603 | int ret; |
| 604 | |
Ben Zhang | 7ed2ffb | 2016-04-22 17:59:40 -0700 | [diff] [blame] | 605 | if (count > SIZE_MAX - sizeof(*tlv)) |
| 606 | return -EINVAL; |
Mythri P K | 45b2d04 | 2014-08-18 15:39:36 +0530 | [diff] [blame] | 607 | tlv = calloc(1, sizeof(*tlv) + count); |
Ben Zhang | 7ed2ffb | 2016-04-22 17:59:40 -0700 | [diff] [blame] | 608 | if (!tlv) |
| 609 | return -ENOMEM; |
Richard Fitzgerald | 899cece | 2014-09-09 17:03:21 +0100 | [diff] [blame] | 610 | tlv->numid = ctl->info.id.numid; |
Mythri P K | 45b2d04 | 2014-08-18 15:39:36 +0530 | [diff] [blame] | 611 | tlv->length = count; |
| 612 | ret = ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_TLV_READ, tlv); |
| 613 | |
| 614 | source = tlv->tlv; |
| 615 | memcpy(array, source, count); |
| 616 | |
| 617 | free(tlv); |
| 618 | |
| 619 | return ret; |
| 620 | } else { |
| 621 | ret = ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_READ, &ev); |
| 622 | if (ret < 0) |
| 623 | return ret; |
| 624 | size = sizeof(ev.value.bytes.data[0]); |
| 625 | source = ev.value.bytes.data; |
| 626 | break; |
| 627 | } |
Simon Wilson | 38f87f3 | 2012-10-23 15:05:23 -0700 | [diff] [blame] | 628 | |
| 629 | default: |
| 630 | return -EINVAL; |
| 631 | } |
| 632 | |
| 633 | memcpy(array, source, size * count); |
Dimitris Papastamos | f51c05b | 2012-05-28 13:40:33 +0100 | [diff] [blame] | 634 | |
| 635 | return 0; |
| 636 | } |
| 637 | |
Taylor Holberton | 4e55719 | 2016-11-23 11:48:06 -0800 | [diff] [blame] | 638 | /** Sets the value of a control, specified by the value index. |
| 639 | * @param ctl An initialized control handle. |
| 640 | * @param id The index of the value within the control. |
| 641 | * @param value The value to set. |
| 642 | * This must be in a range specified by @ref mixer_ctl_get_range_min |
| 643 | * and @ref mixer_ctl_get_range_max. |
| 644 | * @returns On success, zero is returned. |
| 645 | * On failure, non-zero is returned. |
| 646 | * @ingroup libtinyalsa-mixer |
| 647 | */ |
Simon Wilson | 066c9f6 | 2011-06-05 18:23:05 -0700 | [diff] [blame] | 648 | int mixer_ctl_set_value(struct mixer_ctl *ctl, unsigned int id, int value) |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 649 | { |
| 650 | struct snd_ctl_elem_value ev; |
Simon Wilson | 193b1c3 | 2011-06-07 23:42:38 -0700 | [diff] [blame] | 651 | int ret; |
Simon Wilson | d2cb503 | 2011-06-04 00:57:17 -0700 | [diff] [blame] | 652 | |
Richard Fitzgerald | 899cece | 2014-09-09 17:03:21 +0100 | [diff] [blame] | 653 | if (!ctl || (id >= ctl->info.count)) |
Simon Wilson | 193b1c3 | 2011-06-07 23:42:38 -0700 | [diff] [blame] | 654 | return -EINVAL; |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 655 | |
| 656 | memset(&ev, 0, sizeof(ev)); |
Richard Fitzgerald | 899cece | 2014-09-09 17:03:21 +0100 | [diff] [blame] | 657 | ev.id.numid = ctl->info.id.numid; |
Simon Wilson | 193b1c3 | 2011-06-07 23:42:38 -0700 | [diff] [blame] | 658 | ret = ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_READ, &ev); |
| 659 | if (ret < 0) |
| 660 | return ret; |
Simon Wilson | a1bb1e0 | 2011-05-26 18:22:00 -0700 | [diff] [blame] | 661 | |
Richard Fitzgerald | 899cece | 2014-09-09 17:03:21 +0100 | [diff] [blame] | 662 | switch (ctl->info.type) { |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 663 | case SNDRV_CTL_ELEM_TYPE_BOOLEAN: |
Simon Wilson | d2cb503 | 2011-06-04 00:57:17 -0700 | [diff] [blame] | 664 | ev.value.integer.value[id] = !!value; |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 665 | break; |
| 666 | |
Simon Wilson | a1bb1e0 | 2011-05-26 18:22:00 -0700 | [diff] [blame] | 667 | case SNDRV_CTL_ELEM_TYPE_INTEGER: |
Baptiste Robert | 6cd7d5f | 2013-08-07 11:32:45 +0200 | [diff] [blame] | 668 | if ((value < mixer_ctl_get_range_min(ctl)) || |
| 669 | (value > mixer_ctl_get_range_max(ctl))) { |
| 670 | return -EINVAL; |
| 671 | } |
| 672 | |
Simon Wilson | d2cb503 | 2011-06-04 00:57:17 -0700 | [diff] [blame] | 673 | ev.value.integer.value[id] = value; |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 674 | break; |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 675 | |
Simon Wilson | 066c9f6 | 2011-06-05 18:23:05 -0700 | [diff] [blame] | 676 | case SNDRV_CTL_ELEM_TYPE_ENUMERATED: |
| 677 | ev.value.enumerated.item[id] = value; |
| 678 | break; |
| 679 | |
David.Coutherut | ce2b634 | 2013-06-11 16:22:57 +0200 | [diff] [blame] | 680 | case SNDRV_CTL_ELEM_TYPE_BYTES: |
| 681 | ev.value.bytes.data[id] = value; |
| 682 | break; |
| 683 | |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 684 | default: |
Simon Wilson | 193b1c3 | 2011-06-07 23:42:38 -0700 | [diff] [blame] | 685 | return -EINVAL; |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 686 | } |
Simon Wilson | a1bb1e0 | 2011-05-26 18:22:00 -0700 | [diff] [blame] | 687 | |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 688 | return ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_WRITE, &ev); |
| 689 | } |
| 690 | |
Taylor Holberton | 4e55719 | 2016-11-23 11:48:06 -0800 | [diff] [blame] | 691 | /** Sets the contents of a control's value array. |
| 692 | * @param ctl An initialized control handle. |
| 693 | * @param array The array containing control values. |
| 694 | * @param count The number of values in the array. |
| 695 | * This must match the number of values in the control. |
| 696 | * The number of values in a control may be accessed via @ref mixer_ctl_get_num_values |
| 697 | * @returns On success, zero. |
| 698 | * On failure, non-zero. |
| 699 | * @ingroup libtinyalsa-mixer |
| 700 | */ |
Simon Wilson | 38f87f3 | 2012-10-23 15:05:23 -0700 | [diff] [blame] | 701 | int mixer_ctl_set_array(struct mixer_ctl *ctl, const void *array, size_t count) |
Dimitris Papastamos | f51c05b | 2012-05-28 13:40:33 +0100 | [diff] [blame] | 702 | { |
| 703 | struct snd_ctl_elem_value ev; |
Simon Wilson | 38f87f3 | 2012-10-23 15:05:23 -0700 | [diff] [blame] | 704 | size_t size; |
| 705 | void *dest; |
Dimitris Papastamos | f51c05b | 2012-05-28 13:40:33 +0100 | [diff] [blame] | 706 | |
Richard Fitzgerald | 899cece | 2014-09-09 17:03:21 +0100 | [diff] [blame] | 707 | if (!ctl || (count > ctl->info.count) || !count || !array) |
Dimitris Papastamos | f51c05b | 2012-05-28 13:40:33 +0100 | [diff] [blame] | 708 | return -EINVAL; |
| 709 | |
| 710 | memset(&ev, 0, sizeof(ev)); |
Richard Fitzgerald | 899cece | 2014-09-09 17:03:21 +0100 | [diff] [blame] | 711 | ev.id.numid = ctl->info.id.numid; |
Dimitris Papastamos | f51c05b | 2012-05-28 13:40:33 +0100 | [diff] [blame] | 712 | |
Richard Fitzgerald | 899cece | 2014-09-09 17:03:21 +0100 | [diff] [blame] | 713 | switch (ctl->info.type) { |
Simon Wilson | 38f87f3 | 2012-10-23 15:05:23 -0700 | [diff] [blame] | 714 | case SNDRV_CTL_ELEM_TYPE_BOOLEAN: |
| 715 | case SNDRV_CTL_ELEM_TYPE_INTEGER: |
| 716 | size = sizeof(ev.value.integer.value[0]); |
| 717 | dest = ev.value.integer.value; |
| 718 | break; |
| 719 | |
| 720 | case SNDRV_CTL_ELEM_TYPE_BYTES: |
Mythri P K | 45b2d04 | 2014-08-18 15:39:36 +0530 | [diff] [blame] | 721 | /* check if this is new bytes TLV */ |
Richard Fitzgerald | 899cece | 2014-09-09 17:03:21 +0100 | [diff] [blame] | 722 | if (ctl->info.access & SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE) { |
Mythri P K | 45b2d04 | 2014-08-18 15:39:36 +0530 | [diff] [blame] | 723 | struct snd_ctl_tlv *tlv; |
| 724 | int ret = 0; |
Ben Zhang | 7ed2ffb | 2016-04-22 17:59:40 -0700 | [diff] [blame] | 725 | if (count > SIZE_MAX - sizeof(*tlv)) |
| 726 | return -EINVAL; |
Mythri P K | 45b2d04 | 2014-08-18 15:39:36 +0530 | [diff] [blame] | 727 | tlv = calloc(1, sizeof(*tlv) + count); |
Ben Zhang | 7ed2ffb | 2016-04-22 17:59:40 -0700 | [diff] [blame] | 728 | if (!tlv) |
| 729 | return -ENOMEM; |
Richard Fitzgerald | 899cece | 2014-09-09 17:03:21 +0100 | [diff] [blame] | 730 | tlv->numid = ctl->info.id.numid; |
Mythri P K | 45b2d04 | 2014-08-18 15:39:36 +0530 | [diff] [blame] | 731 | tlv->length = count; |
| 732 | memcpy(tlv->tlv, array, count); |
| 733 | |
| 734 | ret = ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_TLV_WRITE, tlv); |
| 735 | free(tlv); |
| 736 | |
| 737 | return ret; |
| 738 | } else { |
| 739 | size = sizeof(ev.value.bytes.data[0]); |
| 740 | dest = ev.value.bytes.data; |
| 741 | } |
Simon Wilson | 38f87f3 | 2012-10-23 15:05:23 -0700 | [diff] [blame] | 742 | break; |
| 743 | |
| 744 | default: |
| 745 | return -EINVAL; |
| 746 | } |
| 747 | |
| 748 | memcpy(dest, array, size * count); |
Dimitris Papastamos | f51c05b | 2012-05-28 13:40:33 +0100 | [diff] [blame] | 749 | |
| 750 | return ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_WRITE, &ev); |
| 751 | } |
| 752 | |
Taylor Holberton | 4e55719 | 2016-11-23 11:48:06 -0800 | [diff] [blame] | 753 | /** Gets the minimum value of an control. |
| 754 | * The control must have an integer type. |
| 755 | * The type of the control can be checked with @ref mixer_ctl_get_type. |
| 756 | * @param ctl An initialized control handle. |
| 757 | * @returns On success, the minimum value of the control. |
| 758 | * On failure, -EINVAL. |
| 759 | * @ingroup libtinyalsa-mixer |
| 760 | */ |
Taylor Holberton | cac43a2 | 2016-12-01 18:11:24 -0800 | [diff] [blame] | 761 | int mixer_ctl_get_range_min(const struct mixer_ctl *ctl) |
Simon Wilson | b9d4f6b | 2011-06-06 14:41:02 -0700 | [diff] [blame] | 762 | { |
Richard Fitzgerald | 899cece | 2014-09-09 17:03:21 +0100 | [diff] [blame] | 763 | if (!ctl || (ctl->info.type != SNDRV_CTL_ELEM_TYPE_INTEGER)) |
Simon Wilson | 193b1c3 | 2011-06-07 23:42:38 -0700 | [diff] [blame] | 764 | return -EINVAL; |
Simon Wilson | b9d4f6b | 2011-06-06 14:41:02 -0700 | [diff] [blame] | 765 | |
Richard Fitzgerald | 899cece | 2014-09-09 17:03:21 +0100 | [diff] [blame] | 766 | return ctl->info.value.integer.min; |
Simon Wilson | b9d4f6b | 2011-06-06 14:41:02 -0700 | [diff] [blame] | 767 | } |
| 768 | |
Taylor Holberton | 4e55719 | 2016-11-23 11:48:06 -0800 | [diff] [blame] | 769 | /** Gets the maximum value of an control. |
| 770 | * The control must have an integer type. |
| 771 | * The type of the control can be checked with @ref mixer_ctl_get_type. |
| 772 | * @param ctl An initialized control handle. |
| 773 | * @returns On success, the maximum value of the control. |
| 774 | * On failure, -EINVAL. |
| 775 | * @ingroup libtinyalsa-mixer |
| 776 | */ |
Taylor Holberton | cac43a2 | 2016-12-01 18:11:24 -0800 | [diff] [blame] | 777 | int mixer_ctl_get_range_max(const struct mixer_ctl *ctl) |
Simon Wilson | b9d4f6b | 2011-06-06 14:41:02 -0700 | [diff] [blame] | 778 | { |
Richard Fitzgerald | 899cece | 2014-09-09 17:03:21 +0100 | [diff] [blame] | 779 | if (!ctl || (ctl->info.type != SNDRV_CTL_ELEM_TYPE_INTEGER)) |
Simon Wilson | 193b1c3 | 2011-06-07 23:42:38 -0700 | [diff] [blame] | 780 | return -EINVAL; |
Simon Wilson | b9d4f6b | 2011-06-06 14:41:02 -0700 | [diff] [blame] | 781 | |
Richard Fitzgerald | 899cece | 2014-09-09 17:03:21 +0100 | [diff] [blame] | 782 | return ctl->info.value.integer.max; |
Simon Wilson | b9d4f6b | 2011-06-06 14:41:02 -0700 | [diff] [blame] | 783 | } |
| 784 | |
Taylor Holberton | 4e55719 | 2016-11-23 11:48:06 -0800 | [diff] [blame] | 785 | /** Get the number of enumerated items in the control. |
| 786 | * @param ctl An initialized control handle. |
| 787 | * @returns The number of enumerated items in the control. |
| 788 | * @ingroup libtinyalsa-mixer |
| 789 | */ |
Taylor Holberton | cac43a2 | 2016-12-01 18:11:24 -0800 | [diff] [blame] | 790 | unsigned int mixer_ctl_get_num_enums(const struct mixer_ctl *ctl) |
Simon Wilson | 066c9f6 | 2011-06-05 18:23:05 -0700 | [diff] [blame] | 791 | { |
Simon Wilson | 193b1c3 | 2011-06-07 23:42:38 -0700 | [diff] [blame] | 792 | if (!ctl) |
Simon Wilson | 066c9f6 | 2011-06-05 18:23:05 -0700 | [diff] [blame] | 793 | return 0; |
Simon Wilson | 066c9f6 | 2011-06-05 18:23:05 -0700 | [diff] [blame] | 794 | |
Richard Fitzgerald | 899cece | 2014-09-09 17:03:21 +0100 | [diff] [blame] | 795 | return ctl->info.value.enumerated.items; |
Simon Wilson | 066c9f6 | 2011-06-05 18:23:05 -0700 | [diff] [blame] | 796 | } |
| 797 | |
David.Coutherut | 9b42396 | 2013-06-03 13:45:51 +0200 | [diff] [blame] | 798 | int mixer_ctl_fill_enum_string(struct mixer_ctl *ctl) |
| 799 | { |
| 800 | struct snd_ctl_elem_info tmp; |
| 801 | unsigned int m; |
| 802 | char **enames; |
| 803 | |
| 804 | if (ctl->ename) { |
| 805 | return 0; |
| 806 | } |
| 807 | |
Taylor Holberton | 6a38d5f | 2016-10-03 21:07:39 -0400 | [diff] [blame] | 808 | enames = calloc(ctl->info.value.enumerated.items, sizeof(char*)); |
David.Coutherut | 9b42396 | 2013-06-03 13:45:51 +0200 | [diff] [blame] | 809 | if (!enames) |
| 810 | goto fail; |
Taylor Holberton | 6a38d5f | 2016-10-03 21:07:39 -0400 | [diff] [blame] | 811 | for (m = 0; m < ctl->info.value.enumerated.items; m++) { |
David.Coutherut | 9b42396 | 2013-06-03 13:45:51 +0200 | [diff] [blame] | 812 | memset(&tmp, 0, sizeof(tmp)); |
Taylor Holberton | 6a38d5f | 2016-10-03 21:07:39 -0400 | [diff] [blame] | 813 | tmp.id.numid = ctl->info.id.numid; |
David.Coutherut | 9b42396 | 2013-06-03 13:45:51 +0200 | [diff] [blame] | 814 | tmp.value.enumerated.item = m; |
| 815 | if (ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_INFO, &tmp) < 0) |
| 816 | goto fail; |
| 817 | enames[m] = strdup(tmp.value.enumerated.name); |
| 818 | if (!enames[m]) |
| 819 | goto fail; |
| 820 | } |
| 821 | ctl->ename = enames; |
| 822 | return 0; |
| 823 | |
| 824 | fail: |
| 825 | if (enames) { |
Taylor Holberton | 6a38d5f | 2016-10-03 21:07:39 -0400 | [diff] [blame] | 826 | for (m = 0; m < ctl->info.value.enumerated.items; m++) { |
David.Coutherut | 9b42396 | 2013-06-03 13:45:51 +0200 | [diff] [blame] | 827 | if (enames[m]) { |
| 828 | free(enames[m]); |
| 829 | } |
| 830 | } |
| 831 | free(enames); |
| 832 | } |
| 833 | return -1; |
| 834 | } |
| 835 | |
Taylor Holberton | 4e55719 | 2016-11-23 11:48:06 -0800 | [diff] [blame] | 836 | /** Gets the string representation of an enumerated item. |
| 837 | * @param ctl An initialized control handle. |
| 838 | * @param enum_id The index of the enumerated value. |
| 839 | * @returns A string representation of the enumerated item. |
| 840 | * @ingroup libtinyalsa-mixer |
| 841 | */ |
Simon Wilson | b29ac1a | 2012-03-08 10:15:08 -0800 | [diff] [blame] | 842 | const char *mixer_ctl_get_enum_string(struct mixer_ctl *ctl, |
| 843 | unsigned int enum_id) |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 844 | { |
Richard Fitzgerald | 899cece | 2014-09-09 17:03:21 +0100 | [diff] [blame] | 845 | if (!ctl || (ctl->info.type != SNDRV_CTL_ELEM_TYPE_ENUMERATED) || |
Taylor Holberton | 6a38d5f | 2016-10-03 21:07:39 -0400 | [diff] [blame] | 846 | (enum_id >= ctl->info.value.enumerated.items) || |
David.Coutherut | 9b42396 | 2013-06-03 13:45:51 +0200 | [diff] [blame] | 847 | mixer_ctl_fill_enum_string(ctl) != 0) |
Simon Wilson | b29ac1a | 2012-03-08 10:15:08 -0800 | [diff] [blame] | 848 | return NULL; |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 849 | |
Simon Wilson | b29ac1a | 2012-03-08 10:15:08 -0800 | [diff] [blame] | 850 | return (const char *)ctl->ename[enum_id]; |
Simon Wilson | 79d3965 | 2011-05-25 13:44:23 -0700 | [diff] [blame] | 851 | } |
| 852 | |
Taylor Holberton | 4e55719 | 2016-11-23 11:48:06 -0800 | [diff] [blame] | 853 | /** Set an enumeration value by string value. |
| 854 | * @param ctl An enumerated mixer control. |
| 855 | * @param string The string representation of an enumeration. |
| 856 | * @returns On success, zero. |
| 857 | * On failure, zero. |
| 858 | * @ingroup libtinyalsa-mixer |
| 859 | */ |
Simon Wilson | f0a20ee | 2011-06-05 21:18:52 -0700 | [diff] [blame] | 860 | int mixer_ctl_set_enum_by_string(struct mixer_ctl *ctl, const char *string) |
| 861 | { |
| 862 | unsigned int i, num_enums; |
| 863 | struct snd_ctl_elem_value ev; |
Simon Wilson | 193b1c3 | 2011-06-07 23:42:38 -0700 | [diff] [blame] | 864 | int ret; |
Simon Wilson | f0a20ee | 2011-06-05 21:18:52 -0700 | [diff] [blame] | 865 | |
Taylor Holberton | 6a38d5f | 2016-10-03 21:07:39 -0400 | [diff] [blame] | 866 | if (!ctl || (ctl->info.type != SNDRV_CTL_ELEM_TYPE_ENUMERATED) || |
David.Coutherut | 9b42396 | 2013-06-03 13:45:51 +0200 | [diff] [blame] | 867 | mixer_ctl_fill_enum_string(ctl) != 0) |
Simon Wilson | 193b1c3 | 2011-06-07 23:42:38 -0700 | [diff] [blame] | 868 | return -EINVAL; |
Simon Wilson | f0a20ee | 2011-06-05 21:18:52 -0700 | [diff] [blame] | 869 | |
Richard Fitzgerald | 899cece | 2014-09-09 17:03:21 +0100 | [diff] [blame] | 870 | num_enums = ctl->info.value.enumerated.items; |
Simon Wilson | f0a20ee | 2011-06-05 21:18:52 -0700 | [diff] [blame] | 871 | for (i = 0; i < num_enums; i++) { |
| 872 | if (!strcmp(string, ctl->ename[i])) { |
| 873 | memset(&ev, 0, sizeof(ev)); |
| 874 | ev.value.enumerated.item[0] = i; |
Richard Fitzgerald | 899cece | 2014-09-09 17:03:21 +0100 | [diff] [blame] | 875 | ev.id.numid = ctl->info.id.numid; |
Simon Wilson | 193b1c3 | 2011-06-07 23:42:38 -0700 | [diff] [blame] | 876 | ret = ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_WRITE, &ev); |
| 877 | if (ret < 0) |
| 878 | return ret; |
Simon Wilson | f0a20ee | 2011-06-05 21:18:52 -0700 | [diff] [blame] | 879 | return 0; |
| 880 | } |
| 881 | } |
| 882 | |
Simon Wilson | 193b1c3 | 2011-06-07 23:42:38 -0700 | [diff] [blame] | 883 | return -EINVAL; |
Simon Wilson | f0a20ee | 2011-06-05 21:18:52 -0700 | [diff] [blame] | 884 | } |
| 885 | |