static void tinymix_list_controls(struct mixer *mixer, int print_all) { struct mixer_ctl *ctl; const char *name, *type; unsigned int num_ctls, num_values; unsigned int i; num_ctls = mixer_get_num_ctls(mixer); printf("Number of controls: %u\n", num_ctls); if (print_all) printf("ctl\ttype\tnum\t%-40svalue\n", "name"); else printf("ctl\ttype\tnum\t%-40s\n", "name"); for (i = 0; i < num_ctls; i++) { ctl = mixer_get_ctl(mixer, i); name = mixer_ctl_get_name(ctl); type = mixer_ctl_get_type_string(ctl); num_values = mixer_ctl_get_num_values(ctl); printf("%u\t%s\t%u\t%-40s", i, type, num_values, name); if (print_all) tinymix_detail_control(mixer, name); printf("\n"); } }
size_t actlstr(char *buf, size_t n, char *ch, struct mixer *mx) { size_t ret; char *status; struct mixer_ctl *ctl; if (!(ctl = mixer_get_ctl_by_name(mx, ch))) { mixer_close(mx); die("couldn't find mixer ctl '%s'\n", ch); } switch (mixer_ctl_get_type(ctl)) { case MIXER_CTL_TYPE_INT: if ((ret = snprintf(buf, n, "%d%%", mixer_ctl_get_percent(ctl, 0))) > n) ret = n; break; case MIXER_CTL_TYPE_BOOL: status = mixer_ctl_get_value(ctl, 0) ? "On" : "Off"; ret = stpncpy(buf, status, n) - buf; break; default: mixer_close(mx); die("unsupported ctl type '%s'\n", mixer_ctl_get_type_string(ctl)); }; return ret; }
TEST_F(MixerTest, tryTinyAlsaTest) { int hwId = AudioHardware::detectAudioHw(); ASSERT_TRUE(hwId >= 0); struct mixer* mixerp = mixer_open(hwId); ASSERT_TRUE(mixerp != NULL); int num_ctls = mixer_get_num_ctls(mixerp); LOGI("Number of mixel control %d", num_ctls); for (int i = 0; i < num_ctls; i++) { struct mixer_ctl* control = mixer_get_ctl(mixerp, i); ASSERT_TRUE(control != NULL); LOGI("Mixer control %s type %s value %d", mixer_ctl_get_name(control), mixer_ctl_get_type_string(control), mixer_ctl_get_num_values(control)); free(control); } // no mixer control for MobilePre. If this assumption fails, // mixer control should be added. ASSERT_TRUE(num_ctls == 0); mixer_close(mixerp); }
static void tinymix_list_controls(struct mixer *mixer) { struct mixer_ctl *ctl; const char *type; unsigned int num_ctls, num_values; char buffer[256]; unsigned int i; num_ctls = mixer_get_num_ctls(mixer); printf("Number of controls: %d\n", num_ctls); printf("ctl\ttype\tnum\t%-40s value\n", "name"); for (i = 0; i < num_ctls; i++) { ctl = mixer_get_ctl(mixer, i); mixer_ctl_get_name(ctl, buffer, sizeof(buffer)); type = mixer_ctl_get_type_string(ctl); num_values = mixer_ctl_get_num_values(ctl); printf("%d\t%s\t%d\t%-40s", i, type, num_values, buffer); tinymix_detail_control(mixer, i, 0); } }
/* Notes: * - param 'line' is modified by this function * - param 'db' has mixer_cache_touch() called on it. */ static void process_line(char* line, struct audio_tool_mixer_cache *db, struct mixer *mixer) { size_t length = strlen(line); size_t pos = 0, sep; const char* sep_ptr; enum field_t { FNAME=0, FTYPE, FCOUNT, FVALS } field = FNAME; unsigned control_id, val, val_no; const char *ctl_type; unsigned file_count, ctl_count; struct mixer_ctl *ctl; if (!length) return; if (line[0] == '#') return; control_id = -1; val_no = 0; while (pos < length) { sep_ptr = strstr(&line[pos], "\t"); if (sep_ptr) sep = (size_t) (sep_ptr - line); else sep = length; if (sep < length) line[sep] = '\0'; switch(field) { case FNAME: control_id = mixer_cache_get_id_by_name(db, &line[pos]); if (control_id == -1) { printf("Error: could not find control %s\n", &line[pos]); pos = length; } ctl = mixer_get_ctl(mixer, control_id); break; case FTYPE: ctl_type = mixer_ctl_get_type_string(ctl); if (0 != strcmp(ctl_type, &line[pos])) { printf("Error: type mismatch for control #%d: file=%s card=%s\n", control_id, &line[pos], ctl_type); pos = length; } break; case FCOUNT: ctl_count = mixer_ctl_get_num_values(ctl); file_count = atoi(&line[pos]); if (ctl_count != file_count) { printf("Error: mismatch in the count of control #%d's values: " "file=%d card=%d\n", control_id, file_count, ctl_count); pos = length; } break; case FVALS: if (0 == strcmp("#N/A", &line[pos])) { pos = length; } else if (0 == strcmp("ENUM", ctl_type)) { mixer_ctl_set_enum_by_string(ctl, &line[pos]); } else { val = atoi(&line[pos]); mixer_ctl_set_value(ctl, val_no, val); } ++val_no; break; } if (field != FVALS) ++field; pos = sep + 1; } mixer_cache_touch(db, control_id); }