/** * \brief return ASCII CTL element identifier name * \param id CTL identifier * \return ascii identifier of CTL element * * The string is allocated using strdup(). */ char *snd_ctl_ascii_elem_id_get(snd_ctl_elem_id_t *id) { unsigned int index, device, subdevice; char buf[256], buf1[32]; snprintf(buf, sizeof(buf), "numid=%u,iface=%s,name='%s'", snd_ctl_elem_id_get_numid(id), snd_ctl_elem_iface_name( snd_ctl_elem_id_get_interface(id)), snd_ctl_elem_id_get_name(id)); buf[sizeof(buf)-1] = '\0'; index = snd_ctl_elem_id_get_index(id); device = snd_ctl_elem_id_get_device(id); subdevice = snd_ctl_elem_id_get_subdevice(id); if (index) { snprintf(buf1, sizeof(buf1), ",index=%i", index); if (strlen(buf) + strlen(buf1) < sizeof(buf)) strcat(buf, buf1); } if (device) { snprintf(buf1, sizeof(buf1), ",device=%i", device); if (strlen(buf) + strlen(buf1) < sizeof(buf)) strcat(buf, buf1); } if (subdevice) { snprintf(buf1, sizeof(buf1), ",subdevice=%i", subdevice); if (strlen(buf) + strlen(buf1) < sizeof(buf)) strcat(buf, buf1); } return strdup(buf); }
static char *id_str(snd_ctl_elem_id_t *id) { static char str[128]; assert(id); sprintf(str, "%i,%i,%i,%s,%i", snd_ctl_elem_id_get_interface(id), snd_ctl_elem_id_get_device(id), snd_ctl_elem_id_get_subdevice(id), snd_ctl_elem_id_get_name(id), snd_ctl_elem_id_get_index(id)); return str; }
static void show_control_id(snd_ctl_elem_id_t *id) { unsigned int index, device, subdevice; printf("numid=%u,iface=%s,name='%s'", snd_ctl_elem_id_get_numid(id), control_iface(id), snd_ctl_elem_id_get_name(id)); index = snd_ctl_elem_id_get_index(id); device = snd_ctl_elem_id_get_device(id); subdevice = snd_ctl_elem_id_get_subdevice(id); if (index) printf(",index=%i", index); if (device) printf(",device=%i", device); if (subdevice) printf(",subdevice=%i", subdevice); }
static int check_elems(struct elem_set_trial *trial) { snd_ctl_elem_value_t *data; unsigned int numid; unsigned int index; unsigned int i; int err; snd_ctl_elem_value_alloca(&data); snd_ctl_elem_value_set_id(data, trial->id); numid = snd_ctl_elem_id_get_numid(trial->id); index = snd_ctl_elem_id_get_index(trial->id); for (i = 0; i < trial->element_count; ++i) { snd_ctl_elem_value_set_index(data, index + i); /* * In Linux 4.0 or former, ioctl(SNDRV_CTL_IOCTL_ELEM_ADD) * doesn't fill all of fields for identification. */ if (numid > 0) snd_ctl_elem_value_set_numid(data, numid + i); err = snd_ctl_elem_read(trial->handle, data); if (err < 0) return err; /* Change members of an element in this element set. */ trial->change_elem_members(trial, data); err = snd_ctl_elem_write(trial->handle, data); if (err < 0) return err; } return 0; }
static void show_control_id(snd_ctl_elem_id_t *id) { unsigned int index, device, subdevice; const char *hctlname; hctlname = snd_ctl_elem_id_get_name(id); LOGV("numid=%u,name='%s'", snd_ctl_elem_id_get_numid(id), hctlname); index = snd_ctl_elem_id_get_index(id); device = snd_ctl_elem_id_get_device(id); subdevice = snd_ctl_elem_id_get_subdevice(id); if (index) LOGV(",index=%i", index); if (device) LOGV(",device=%i", device); if (subdevice) LOGV(",subdevice=%i", subdevice); /* For we just need to get to know that whether there is a control for "Playback" and "control" * we just pick up these two elements */ if (strstr(hctlname,"Playback Volume")|| strstr(hctlname, "Capture Volume")) LOGD("found placback/capture volume"); }
static int check_elem_set_props(struct elem_set_trial *trial) { snd_ctl_elem_id_t *id; snd_ctl_elem_info_t *info; unsigned int numid; unsigned int index; unsigned int i; unsigned int j; int err; snd_ctl_elem_id_alloca(&id); snd_ctl_elem_info_alloca(&info); snd_ctl_elem_info_set_id(info, trial->id); numid = snd_ctl_elem_id_get_numid(trial->id); index = snd_ctl_elem_id_get_index(trial->id); for (i = 0; i < trial->element_count; ++i) { snd_ctl_elem_info_set_index(info, index + i); /* * In Linux 4.0 or former, ioctl(SNDRV_CTL_IOCTL_ELEM_ADD) * doesn't fill all of fields for identification. */ if (numid > 0) snd_ctl_elem_info_set_numid(info, numid + i); err = snd_ctl_elem_info(trial->handle, info); if (err < 0) return err; /* Check some common properties. */ if (snd_ctl_elem_info_get_type(info) != trial->type) return -EIO; if (snd_ctl_elem_info_get_count(info) != trial->member_count) return -EIO; for (j = 0; j < 4; ++j) { if (snd_ctl_elem_info_get_dimension(info, j) != trial->dimension[j]) return -EIO; } /* * In a case of IPC, this is the others. But in this case, * it's myself. */ if (snd_ctl_elem_info_get_owner(info) != getpid()) return -EIO; /* * Just adding an element set by userspace applications, * included elements are initially locked. */ if (!snd_ctl_elem_info_is_locked(info)) return -EIO; /* Check type-specific properties. */ if (trial->check_elem_props != NULL) { err = trial->check_elem_props(trial, info); if (err < 0) return err; } snd_ctl_elem_info_get_id(info, id); err = snd_ctl_elem_unlock(trial->handle, id); if (err < 0) return err; } return 0; }