aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Wilson2012-03-08 12:45:31 -0600
committerSimon Wilson2012-03-08 12:45:35 -0600
commite44e30a90293ffebe604efea37842aff9d5da874 (patch)
tree1661cc33d97ff5a7a42542eecbe02843bc0fadd5
parentdaa83291944318d8face12c780dfb69ae96b0723 (diff)
downloadplatform-external-tinyalsa-e44e30a90293ffebe604efea37842aff9d5da874.tar.gz
platform-external-tinyalsa-e44e30a90293ffebe604efea37842aff9d5da874.tar.xz
platform-external-tinyalsa-e44e30a90293ffebe604efea37842aff9d5da874.zip
Update to latest tinyalsa
8fe2c93 mixer: remove redundant IOCTL_ELEM_READs b29ac1a mixer: simplify string get APIs 174d874 tinycap: add missing options to usage string Change-Id: Id91acf6a084dac3dd0d07966330e10ffc95618bd
-rw-r--r--include/tinyalsa/asoundlib.h6
-rw-r--r--mixer.c39
-rw-r--r--tinycap.c2
-rw-r--r--tinymix.c19
4 files changed, 20 insertions, 46 deletions
diff --git a/include/tinyalsa/asoundlib.h b/include/tinyalsa/asoundlib.h
index 655fe76..f3587ab 100644
--- a/include/tinyalsa/asoundlib.h
+++ b/include/tinyalsa/asoundlib.h
@@ -176,13 +176,13 @@ struct mixer_ctl *mixer_get_ctl(struct mixer *mixer, unsigned int id);
176struct mixer_ctl *mixer_get_ctl_by_name(struct mixer *mixer, const char *name); 176struct mixer_ctl *mixer_get_ctl_by_name(struct mixer *mixer, const char *name);
177 177
178/* Get info about mixer controls */ 178/* Get info about mixer controls */
179int mixer_ctl_get_name(struct mixer_ctl *ctl, char *name, unsigned int size); 179const char *mixer_ctl_get_name(struct mixer_ctl *ctl);
180enum mixer_ctl_type mixer_ctl_get_type(struct mixer_ctl *ctl); 180enum mixer_ctl_type mixer_ctl_get_type(struct mixer_ctl *ctl);
181const char *mixer_ctl_get_type_string(struct mixer_ctl *ctl); 181const char *mixer_ctl_get_type_string(struct mixer_ctl *ctl);
182unsigned int mixer_ctl_get_num_values(struct mixer_ctl *ctl); 182unsigned int mixer_ctl_get_num_values(struct mixer_ctl *ctl);
183unsigned int mixer_ctl_get_num_enums(struct mixer_ctl *ctl); 183unsigned int mixer_ctl_get_num_enums(struct mixer_ctl *ctl);
184int mixer_ctl_get_enum_string(struct mixer_ctl *ctl, unsigned int enum_id, 184const char *mixer_ctl_get_enum_string(struct mixer_ctl *ctl,
185 char *string, unsigned int size); 185 unsigned int enum_id);
186 186
187/* Set and get mixer controls */ 187/* Set and get mixer controls */
188int mixer_ctl_get_percent(struct mixer_ctl *ctl, unsigned int id); 188int mixer_ctl_get_percent(struct mixer_ctl *ctl, unsigned int id);
diff --git a/mixer.c b/mixer.c
index a7f5d21..4a39a43 100644
--- a/mixer.c
+++ b/mixer.c
@@ -193,13 +193,12 @@ struct mixer_ctl *mixer_get_ctl_by_name(struct mixer *mixer, const char *name)
193 return NULL; 193 return NULL;
194} 194}
195 195
196int mixer_ctl_get_name(struct mixer_ctl *ctl, char *name, unsigned int size) 196const char *mixer_ctl_get_name(struct mixer_ctl *ctl)
197{ 197{
198 if (!ctl || !name || (size == 0)) 198 if (!ctl)
199 return -EINVAL; 199 return NULL;
200 200
201 strncpy(name, (char *)ctl->info->id.name, size); 201 return (const char *)ctl->info->id.name;
202 return 0;
203} 202}
204 203
205enum mixer_ctl_type mixer_ctl_get_type(struct mixer_ctl *ctl) 204enum mixer_ctl_type mixer_ctl_get_type(struct mixer_ctl *ctl)
@@ -352,35 +351,21 @@ int mixer_ctl_set_value(struct mixer_ctl *ctl, unsigned int id, int value)
352 351
353int mixer_ctl_get_range_min(struct mixer_ctl *ctl) 352int mixer_ctl_get_range_min(struct mixer_ctl *ctl)
354{ 353{
355 struct snd_ctl_elem_value ev;
356 int ret; 354 int ret;
357 355
358 if (!ctl || (ctl->info->type != SNDRV_CTL_ELEM_TYPE_INTEGER)) 356 if (!ctl || (ctl->info->type != SNDRV_CTL_ELEM_TYPE_INTEGER))
359 return -EINVAL; 357 return -EINVAL;
360 358
361 memset(&ev, 0, sizeof(ev));
362 ev.id.numid = ctl->info->id.numid;
363 ret = ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_READ, &ev);
364 if (ret < 0)
365 return ret;
366
367 return ctl->info->value.integer.min; 359 return ctl->info->value.integer.min;
368} 360}
369 361
370int mixer_ctl_get_range_max(struct mixer_ctl *ctl) 362int mixer_ctl_get_range_max(struct mixer_ctl *ctl)
371{ 363{
372 struct snd_ctl_elem_value ev;
373 int ret; 364 int ret;
374 365
375 if (!ctl || (ctl->info->type != SNDRV_CTL_ELEM_TYPE_INTEGER)) 366 if (!ctl || (ctl->info->type != SNDRV_CTL_ELEM_TYPE_INTEGER))
376 return -EINVAL; 367 return -EINVAL;
377 368
378 memset(&ev, 0, sizeof(ev));
379 ev.id.numid = ctl->info->id.numid;
380 ret = ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_READ, &ev);
381 if (ret < 0)
382 return ret;
383
384 return ctl->info->value.integer.max; 369 return ctl->info->value.integer.max;
385} 370}
386 371
@@ -392,24 +377,16 @@ unsigned int mixer_ctl_get_num_enums(struct mixer_ctl *ctl)
392 return ctl->info->value.enumerated.items; 377 return ctl->info->value.enumerated.items;
393} 378}
394 379
395int mixer_ctl_get_enum_string(struct mixer_ctl *ctl, unsigned int enum_id, 380const char *mixer_ctl_get_enum_string(struct mixer_ctl *ctl,
396 char *string, unsigned int size) 381 unsigned int enum_id)
397{ 382{
398 struct snd_ctl_elem_value ev;
399 int ret; 383 int ret;
400 384
401 if (!ctl || (ctl->info->type != SNDRV_CTL_ELEM_TYPE_ENUMERATED) || 385 if (!ctl || (ctl->info->type != SNDRV_CTL_ELEM_TYPE_ENUMERATED) ||
402 (enum_id >= ctl->info->value.enumerated.items)) 386 (enum_id >= ctl->info->value.enumerated.items))
403 return -EINVAL; 387 return NULL;
404
405 memset(&ev, 0, sizeof(ev));
406 ev.id.numid = ctl->info->id.numid;
407 ret = ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_READ, &ev);
408 if (ret < 0)
409 return ret;
410 strncpy(string, (char *)ctl->ename[enum_id], size);
411 388
412 return 0; 389 return (const char *)ctl->ename[enum_id];
413} 390}
414 391
415int mixer_ctl_set_enum_by_string(struct mixer_ctl *ctl, const char *string) 392int mixer_ctl_set_enum_by_string(struct mixer_ctl *ctl, const char *string)
diff --git a/tinycap.c b/tinycap.c
index a50c417..dcc238c 100644
--- a/tinycap.c
+++ b/tinycap.c
@@ -82,7 +82,7 @@ int main(int argc, char **argv)
82 82
83 if (argc < 2) { 83 if (argc < 2) {
84 fprintf(stderr, "Usage: %s file.wav [-D card] [-d device] [-c channels] " 84 fprintf(stderr, "Usage: %s file.wav [-D card] [-d device] [-c channels] "
85 "[-r rate] [-b bits]\n", argv[0]); 85 "[-r rate] [-b bits] [-p period_size] [-n n_periods]\n", argv[0]);
86 return 1; 86 return 1;
87 } 87 }
88 88
diff --git a/tinymix.c b/tinymix.c
index e7bd276..6427a02 100644
--- a/tinymix.c
+++ b/tinymix.c
@@ -77,9 +77,8 @@ int main(int argc, char **argv)
77static void tinymix_list_controls(struct mixer *mixer) 77static void tinymix_list_controls(struct mixer *mixer)
78{ 78{
79 struct mixer_ctl *ctl; 79 struct mixer_ctl *ctl;
80 const char *type; 80 const char *name, *type;
81 unsigned int num_ctls, num_values; 81 unsigned int num_ctls, num_values;
82 char buffer[256];
83 unsigned int i; 82 unsigned int i;
84 83
85 num_ctls = mixer_get_num_ctls(mixer); 84 num_ctls = mixer_get_num_ctls(mixer);
@@ -90,10 +89,10 @@ static void tinymix_list_controls(struct mixer *mixer)
90 for (i = 0; i < num_ctls; i++) { 89 for (i = 0; i < num_ctls; i++) {
91 ctl = mixer_get_ctl(mixer, i); 90 ctl = mixer_get_ctl(mixer, i);
92 91
93 mixer_ctl_get_name(ctl, buffer, sizeof(buffer)); 92 name = mixer_ctl_get_name(ctl);
94 type = mixer_ctl_get_type_string(ctl); 93 type = mixer_ctl_get_type_string(ctl);
95 num_values = mixer_ctl_get_num_values(ctl); 94 num_values = mixer_ctl_get_num_values(ctl);
96 printf("%d\t%s\t%d\t%-40s", i, type, num_values, buffer); 95 printf("%d\t%s\t%d\t%-40s", i, type, num_values, name);
97 tinymix_detail_control(mixer, i, 0); 96 tinymix_detail_control(mixer, i, 0);
98 } 97 }
99} 98}
@@ -101,18 +100,18 @@ static void tinymix_list_controls(struct mixer *mixer)
101static void tinymix_print_enum(struct mixer_ctl *ctl, int print_all) 100static void tinymix_print_enum(struct mixer_ctl *ctl, int print_all)
102{ 101{
103 unsigned int num_enums; 102 unsigned int num_enums;
104 char buffer[256];
105 unsigned int i; 103 unsigned int i;
104 const char *string;
106 105
107 num_enums = mixer_ctl_get_num_enums(ctl); 106 num_enums = mixer_ctl_get_num_enums(ctl);
108 107
109 for (i = 0; i < num_enums; i++) { 108 for (i = 0; i < num_enums; i++) {
110 mixer_ctl_get_enum_string(ctl, i, buffer, sizeof(buffer)); 109 string = mixer_ctl_get_enum_string(ctl, i);
111 if (print_all) 110 if (print_all)
112 printf("\t%s%s", mixer_ctl_get_value(ctl, 0) == (int)i ? ">" : "", 111 printf("\t%s%s", mixer_ctl_get_value(ctl, 0) == (int)i ? ">" : "",
113 buffer); 112 string);
114 else if (mixer_ctl_get_value(ctl, 0) == (int)i) 113 else if (mixer_ctl_get_value(ctl, 0) == (int)i)
115 printf(" %-s", buffer); 114 printf(" %-s", string);
116 } 115 }
117} 116}
118 117
@@ -122,7 +121,6 @@ static void tinymix_detail_control(struct mixer *mixer, unsigned int id,
122 struct mixer_ctl *ctl; 121 struct mixer_ctl *ctl;
123 enum mixer_ctl_type type; 122 enum mixer_ctl_type type;
124 unsigned int num_values; 123 unsigned int num_values;
125 char buffer[256];
126 unsigned int i; 124 unsigned int i;
127 int min, max; 125 int min, max;
128 126
@@ -133,12 +131,11 @@ static void tinymix_detail_control(struct mixer *mixer, unsigned int id,
133 131
134 ctl = mixer_get_ctl(mixer, id); 132 ctl = mixer_get_ctl(mixer, id);
135 133
136 mixer_ctl_get_name(ctl, buffer, sizeof(buffer));
137 type = mixer_ctl_get_type(ctl); 134 type = mixer_ctl_get_type(ctl);
138 num_values = mixer_ctl_get_num_values(ctl); 135 num_values = mixer_ctl_get_num_values(ctl);
139 136
140 if (print_all) 137 if (print_all)
141 printf("%s:", buffer); 138 printf("%s:", mixer_ctl_get_name(ctl));
142 139
143 for (i = 0; i < num_values; i++) { 140 for (i = 0; i < num_values; i++) {
144 switch (type) 141 switch (type)