mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-11-03 09:01:52 -05:00
Better names for control API
This commit is contained in:
parent
66f13f6115
commit
45c416ed82
22 changed files with 666 additions and 668 deletions
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Control Interface - highlevel API - hcontrol bag operations
|
||||
* Control Interface - highlevel API - helem bag operations
|
||||
* Copyright (c) 2000 by Jaroslav Kysela <perex@suse.cz>
|
||||
*
|
||||
*
|
||||
|
|
@ -36,43 +36,43 @@ int snd_ctl_hbag_create(void **bag)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void snd_ctl_hbag_free_private(snd_hcontrol_t *hcontrol ATTRIBUTE_UNUSED)
|
||||
static void snd_ctl_hbag_free_private(snd_hctl_element_t *helem ATTRIBUTE_UNUSED)
|
||||
{
|
||||
/* nothing */
|
||||
}
|
||||
|
||||
int snd_ctl_hbag_destroy(void **bag, void (*hcontrol_free)(snd_hcontrol_t *hcontrol))
|
||||
int snd_ctl_hbag_destroy(void **bag, void (*hctl_element_free)(snd_hctl_element_t *helem))
|
||||
{
|
||||
assert(bag != NULL);
|
||||
if (hcontrol_free == NULL)
|
||||
hcontrol_free = snd_ctl_hbag_free_private;
|
||||
tdestroy(*bag, (__free_fn_t)hcontrol_free);
|
||||
if (hctl_element_free == NULL)
|
||||
hctl_element_free = snd_ctl_hbag_free_private;
|
||||
tdestroy(*bag, (__free_fn_t)hctl_element_free);
|
||||
*bag = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int snd_ctl_hbag_add(void **bag, snd_hcontrol_t *hcontrol)
|
||||
int snd_ctl_hbag_add(void **bag, snd_hctl_element_t *helem)
|
||||
{
|
||||
void *res;
|
||||
|
||||
assert(bag != NULL && hcontrol != NULL);
|
||||
res = tsearch(hcontrol, bag, (__compar_fn_t)snd_ctl_hsort);
|
||||
assert(bag != NULL && helem != NULL);
|
||||
res = tsearch(helem, bag, (__compar_fn_t)snd_ctl_hsort);
|
||||
if (res == NULL)
|
||||
return -ENOMEM;
|
||||
if ((snd_hcontrol_t *)res == hcontrol)
|
||||
if ((snd_hctl_element_t *)res == helem)
|
||||
return -EALREADY;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int snd_ctl_hbag_del(void **bag, snd_hcontrol_t *hcontrol)
|
||||
int snd_ctl_hbag_del(void **bag, snd_hctl_element_t *helem)
|
||||
{
|
||||
assert(bag != NULL && hcontrol != NULL);
|
||||
if (tdelete(hcontrol, bag, (__compar_fn_t)snd_ctl_hsort) == NULL)
|
||||
assert(bag != NULL && helem != NULL);
|
||||
if (tdelete(helem, bag, (__compar_fn_t)snd_ctl_hsort) == NULL)
|
||||
return -ENOENT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
snd_hcontrol_t *snd_ctl_hbag_find(void **bag, snd_control_id_t *id)
|
||||
snd_hctl_element_t *snd_ctl_hbag_find(void **bag, snd_ctl_element_id_t *id)
|
||||
{
|
||||
void *res;
|
||||
|
||||
|
|
@ -80,5 +80,5 @@ snd_hcontrol_t *snd_ctl_hbag_find(void **bag, snd_control_id_t *id)
|
|||
if (*bag == NULL)
|
||||
return NULL;
|
||||
res = tfind(id, bag, (__compar_fn_t)snd_ctl_hsort);
|
||||
return res == NULL ? NULL : *(snd_hcontrol_t **)res;
|
||||
return res == NULL ? NULL : *(snd_hctl_element_t **)res;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ int snd_card_get_index(const char *string)
|
|||
{
|
||||
int card;
|
||||
snd_ctl_t *handle;
|
||||
snd_ctl_info_t info;
|
||||
snd_ctl_card_info_t info;
|
||||
|
||||
if (!string || *string == '\0')
|
||||
return -EINVAL;
|
||||
|
|
@ -90,7 +90,7 @@ int snd_card_get_index(const char *string)
|
|||
continue;
|
||||
if (snd_ctl_hw_open(&handle, NULL, card) < 0)
|
||||
continue;
|
||||
if (snd_ctl_info(handle, &info) < 0) {
|
||||
if (snd_ctl_card_info(handle, &info) < 0) {
|
||||
snd_ctl_close(handle);
|
||||
continue;
|
||||
}
|
||||
|
|
@ -104,14 +104,14 @@ int snd_card_get_index(const char *string)
|
|||
int snd_card_get_name(int card, char **name)
|
||||
{
|
||||
snd_ctl_t *handle;
|
||||
snd_ctl_info_t info;
|
||||
snd_ctl_card_info_t info;
|
||||
int err;
|
||||
|
||||
if (name == NULL)
|
||||
return -EINVAL;
|
||||
if ((err = snd_ctl_hw_open(&handle, NULL, card)) < 0)
|
||||
return err;
|
||||
if ((err = snd_ctl_info(handle, &info)) < 0) {
|
||||
if ((err = snd_ctl_card_info(handle, &info)) < 0) {
|
||||
snd_ctl_close(handle);
|
||||
return err;
|
||||
}
|
||||
|
|
@ -125,14 +125,14 @@ int snd_card_get_name(int card, char **name)
|
|||
int snd_card_get_longname(int card, char **name)
|
||||
{
|
||||
snd_ctl_t *handle;
|
||||
snd_ctl_info_t info;
|
||||
snd_ctl_card_info_t info;
|
||||
int err;
|
||||
|
||||
if (name == NULL)
|
||||
return -EINVAL;
|
||||
if ((err = snd_ctl_hw_open(&handle, NULL, card)) < 0)
|
||||
return err;
|
||||
if ((err = snd_ctl_info(handle, &info)) < 0) {
|
||||
if ((err = snd_ctl_card_info(handle, &info)) < 0) {
|
||||
snd_ctl_close(handle);
|
||||
return err;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,31 +48,31 @@ int snd_ctl_poll_descriptor(snd_ctl_t *ctl)
|
|||
return ctl->ops->poll_descriptor(ctl);
|
||||
}
|
||||
|
||||
int snd_ctl_info(snd_ctl_t *ctl, snd_ctl_info_t *info)
|
||||
int snd_ctl_card_info(snd_ctl_t *ctl, snd_ctl_card_info_t *info)
|
||||
{
|
||||
assert(ctl && info);
|
||||
return ctl->ops->hw_info(ctl, info);
|
||||
}
|
||||
|
||||
int snd_ctl_clist(snd_ctl_t *ctl, snd_control_list_t *list)
|
||||
int snd_ctl_clist(snd_ctl_t *ctl, snd_ctl_element_list_t *list)
|
||||
{
|
||||
assert(ctl && list);
|
||||
return ctl->ops->clist(ctl, list);
|
||||
}
|
||||
|
||||
int snd_ctl_cinfo(snd_ctl_t *ctl, snd_control_info_t *info)
|
||||
int snd_ctl_element_info(snd_ctl_t *ctl, snd_ctl_element_info_t *info)
|
||||
{
|
||||
assert(ctl && info && (info->id.name[0] || info->id.numid));
|
||||
return ctl->ops->cinfo(ctl, info);
|
||||
}
|
||||
|
||||
int snd_ctl_cread(snd_ctl_t *ctl, snd_control_t *control)
|
||||
int snd_ctl_element_read(snd_ctl_t *ctl, snd_ctl_element_t *control)
|
||||
{
|
||||
assert(ctl && control && (control->id.name[0] || control->id.numid));
|
||||
return ctl->ops->cread(ctl, control);
|
||||
}
|
||||
|
||||
int snd_ctl_cwrite(snd_ctl_t *ctl, snd_control_t *control)
|
||||
int snd_ctl_element_write(snd_ctl_t *ctl, snd_ctl_element_t *control)
|
||||
{
|
||||
assert(ctl && control && (control->id.name[0] || control->id.numid));
|
||||
return ctl->ops->cwrite(ctl, control);
|
||||
|
|
@ -239,18 +239,18 @@ int snd_ctl_open(snd_ctl_t **ctlp, char *name)
|
|||
return open_func(ctlp, name, ctl_conf);
|
||||
}
|
||||
|
||||
void snd_control_set_bytes(snd_control_t *obj, void *data, size_t size)
|
||||
void snd_ctl_element_set_bytes(snd_ctl_element_t *obj, void *data, size_t size)
|
||||
{
|
||||
assert(obj);
|
||||
assert(size <= sizeof(obj->value.bytes.data));
|
||||
memcpy(obj->value.bytes.data, data, size);
|
||||
}
|
||||
|
||||
#define TYPE(v) [SND_CONTROL_TYPE_##v] = #v
|
||||
#define IFACE(v) [SND_CONTROL_IFACE_##v] = #v
|
||||
#define TYPE(v) [SND_CTL_ELEMENT_TYPE_##v] = #v
|
||||
#define IFACE(v) [SND_CTL_ELEMENT_IFACE_##v] = #v
|
||||
#define EVENT(v) [SND_CTL_EVENT_##v] = #v
|
||||
|
||||
const char *snd_control_type_names[] = {
|
||||
const char *snd_ctl_element_type_names[] = {
|
||||
TYPE(NONE),
|
||||
TYPE(BOOLEAN),
|
||||
TYPE(INTEGER),
|
||||
|
|
@ -259,7 +259,7 @@ const char *snd_control_type_names[] = {
|
|||
TYPE(IEC958),
|
||||
};
|
||||
|
||||
const char *snd_control_iface_names[] = {
|
||||
const char *snd_ctl_element_iface_names[] = {
|
||||
IFACE(CARD),
|
||||
IFACE(HWDEP),
|
||||
IFACE(MIXER),
|
||||
|
|
@ -277,16 +277,16 @@ const char *snd_ctl_event_type_names[] = {
|
|||
EVENT(REMOVE),
|
||||
};
|
||||
|
||||
const char *snd_control_type_name(snd_control_type_t type)
|
||||
const char *snd_ctl_element_type_name(snd_ctl_element_type_t type)
|
||||
{
|
||||
assert(type <= SND_CONTROL_TYPE_LAST);
|
||||
return snd_control_type_names[snd_enum_to_int(type)];
|
||||
assert(type <= SND_CTL_ELEMENT_TYPE_LAST);
|
||||
return snd_ctl_element_type_names[snd_enum_to_int(type)];
|
||||
}
|
||||
|
||||
const char *snd_control_iface_name(snd_control_iface_t iface)
|
||||
const char *snd_ctl_element_iface_name(snd_ctl_element_iface_t iface)
|
||||
{
|
||||
assert(iface <= SND_CONTROL_IFACE_LAST);
|
||||
return snd_control_iface_names[snd_enum_to_int(iface)];
|
||||
assert(iface <= SND_CTL_ELEMENT_IFACE_LAST);
|
||||
return snd_ctl_element_iface_names[snd_enum_to_int(iface)];
|
||||
}
|
||||
|
||||
const char *snd_ctl_event_type_name(snd_ctl_event_type_t type)
|
||||
|
|
@ -295,7 +295,7 @@ const char *snd_ctl_event_type_name(snd_ctl_event_type_t type)
|
|||
return snd_ctl_event_type_names[snd_enum_to_int(type)];
|
||||
}
|
||||
|
||||
int snd_control_list_alloc_space(snd_control_list_t *obj, unsigned int entries)
|
||||
int snd_ctl_element_list_alloc_space(snd_ctl_element_list_t *obj, unsigned int entries)
|
||||
{
|
||||
obj->pids = calloc(entries, sizeof(*obj->pids));
|
||||
if (!obj->pids) {
|
||||
|
|
@ -306,7 +306,7 @@ int snd_control_list_alloc_space(snd_control_list_t *obj, unsigned int entries)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void snd_control_list_free_space(snd_control_list_t *obj)
|
||||
void snd_ctl_element_list_free_space(snd_ctl_element_list_t *obj)
|
||||
{
|
||||
free(obj->pids);
|
||||
obj->pids = NULL;
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ static int snd_ctl_hw_poll_descriptor(snd_ctl_t *handle)
|
|||
return hw->fd;
|
||||
}
|
||||
|
||||
static int snd_ctl_hw_hw_info(snd_ctl_t *handle, snd_ctl_info_t *info)
|
||||
static int snd_ctl_hw_hw_info(snd_ctl_t *handle, snd_ctl_card_info_t *info)
|
||||
{
|
||||
snd_ctl_hw_t *hw = handle->private;
|
||||
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_INFO, info) < 0)
|
||||
|
|
@ -59,34 +59,34 @@ static int snd_ctl_hw_hw_info(snd_ctl_t *handle, snd_ctl_info_t *info)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int snd_ctl_hw_clist(snd_ctl_t *handle, snd_control_list_t *list)
|
||||
static int snd_ctl_hw_clist(snd_ctl_t *handle, snd_ctl_element_list_t *list)
|
||||
{
|
||||
snd_ctl_hw_t *hw = handle->private;
|
||||
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_CONTROL_LIST, list) < 0)
|
||||
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_ELEMENT_LIST, list) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int snd_ctl_hw_cinfo(snd_ctl_t *handle, snd_control_info_t *info)
|
||||
static int snd_ctl_hw_cinfo(snd_ctl_t *handle, snd_ctl_element_info_t *info)
|
||||
{
|
||||
snd_ctl_hw_t *hw = handle->private;
|
||||
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_CONTROL_INFO, info) < 0)
|
||||
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_ELEMENT_INFO, info) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int snd_ctl_hw_cread(snd_ctl_t *handle, snd_control_t *control)
|
||||
static int snd_ctl_hw_cread(snd_ctl_t *handle, snd_ctl_element_t *control)
|
||||
{
|
||||
snd_ctl_hw_t *hw = handle->private;
|
||||
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_CONTROL_READ, control) < 0)
|
||||
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_ELEMENT_READ, control) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int snd_ctl_hw_cwrite(snd_ctl_t *handle, snd_control_t *control)
|
||||
static int snd_ctl_hw_cwrite(snd_ctl_t *handle, snd_ctl_element_t *control)
|
||||
{
|
||||
snd_ctl_hw_t *hw = handle->private;
|
||||
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_CONTROL_WRITE, control) < 0)
|
||||
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_ELEMENT_WRITE, control) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,11 +25,11 @@
|
|||
typedef struct _snd_ctl_ops {
|
||||
int (*close)(snd_ctl_t *handle);
|
||||
int (*poll_descriptor)(snd_ctl_t *handle);
|
||||
int (*hw_info)(snd_ctl_t *handle, snd_ctl_info_t *info);
|
||||
int (*clist)(snd_ctl_t *handle, snd_control_list_t *list);
|
||||
int (*cinfo)(snd_ctl_t *handle, snd_control_info_t *info);
|
||||
int (*cread)(snd_ctl_t *handle, snd_control_t *control);
|
||||
int (*cwrite)(snd_ctl_t *handle, snd_control_t *control);
|
||||
int (*hw_info)(snd_ctl_t *handle, snd_ctl_card_info_t *info);
|
||||
int (*clist)(snd_ctl_t *handle, snd_ctl_element_list_t *list);
|
||||
int (*cinfo)(snd_ctl_t *handle, snd_ctl_element_info_t *info);
|
||||
int (*cread)(snd_ctl_t *handle, snd_ctl_element_t *control);
|
||||
int (*cwrite)(snd_ctl_t *handle, snd_ctl_element_t *control);
|
||||
int (*hwdep_next_device)(snd_ctl_t *handle, int *device);
|
||||
int (*hwdep_info)(snd_ctl_t *handle, snd_hwdep_info_t * info);
|
||||
int (*pcm_next_device)(snd_ctl_t *handle, int *device);
|
||||
|
|
@ -62,33 +62,33 @@ struct _snd_ctl {
|
|||
struct _snd_ctl_callbacks {
|
||||
void *private_data; /* may be used by an application */
|
||||
void (*rebuild) (snd_ctl_t *handle, void *private_data);
|
||||
void (*value) (snd_ctl_t *handle, void *private_data, snd_control_id_t * id);
|
||||
void (*change) (snd_ctl_t *handle, void *private_data, snd_control_id_t * id);
|
||||
void (*add) (snd_ctl_t *handle, void *private_data, snd_control_id_t * id);
|
||||
void (*remove) (snd_ctl_t *handle, void *private_data, snd_control_id_t * id);
|
||||
void (*value) (snd_ctl_t *handle, void *private_data, snd_ctl_element_id_t * id);
|
||||
void (*change) (snd_ctl_t *handle, void *private_data, snd_ctl_element_id_t * id);
|
||||
void (*add) (snd_ctl_t *handle, void *private_data, snd_ctl_element_id_t * id);
|
||||
void (*remove) (snd_ctl_t *handle, void *private_data, snd_ctl_element_id_t * id);
|
||||
void *reserved[58]; /* reserved for the future use - must be NULL!!! */
|
||||
};
|
||||
|
||||
struct _snd_hcontrol_list {
|
||||
struct _snd_hctl_element_list {
|
||||
unsigned int offset; /* W: first control ID to get */
|
||||
unsigned int space; /* W: count of control IDs to get */
|
||||
unsigned int used; /* R: count of available (set) controls */
|
||||
unsigned int count; /* R: count of all available controls */
|
||||
snd_control_id_t *pids; /* W: IDs */
|
||||
snd_ctl_element_id_t *pids; /* W: IDs */
|
||||
};
|
||||
|
||||
struct _snd_hcontrol {
|
||||
snd_control_id_t id; /* must be always on top */
|
||||
struct list_head list; /* links for list of all hcontrols */
|
||||
struct _snd_hctl_element {
|
||||
snd_ctl_element_id_t id; /* must be always on top */
|
||||
struct list_head list; /* links for list of all helems */
|
||||
int change: 1, /* structure change */
|
||||
value: 1; /* value change */
|
||||
/* event callbacks */
|
||||
snd_hcontrol_callback_t callback_change;
|
||||
snd_hcontrol_callback_t callback_value;
|
||||
snd_hcontrol_callback_t callback_remove;
|
||||
snd_hctl_element_callback_t callback_change;
|
||||
snd_hctl_element_callback_t callback_value;
|
||||
snd_hctl_element_callback_t callback_remove;
|
||||
/* private data */
|
||||
void *private_data;
|
||||
snd_hcontrol_private_free_t private_free;
|
||||
snd_hctl_element_private_free_t private_free;
|
||||
/* links */
|
||||
snd_ctl_t *handle; /* associated handle */
|
||||
};
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -106,7 +106,7 @@ static int snd_ctl_shm_poll_descriptor(snd_ctl_t *ctl)
|
|||
return fd;
|
||||
}
|
||||
|
||||
static int snd_ctl_shm_hw_info(snd_ctl_t *ctl, snd_ctl_info_t *info)
|
||||
static int snd_ctl_shm_hw_info(snd_ctl_t *ctl, snd_ctl_card_info_t *info)
|
||||
{
|
||||
snd_ctl_shm_t *shm = ctl->private;
|
||||
volatile snd_ctl_shm_ctrl_t *ctrl = shm->ctrl;
|
||||
|
|
@ -120,18 +120,18 @@ static int snd_ctl_shm_hw_info(snd_ctl_t *ctl, snd_ctl_info_t *info)
|
|||
return err;
|
||||
}
|
||||
|
||||
static int snd_ctl_shm_clist(snd_ctl_t *ctl, snd_control_list_t *list)
|
||||
static int snd_ctl_shm_clist(snd_ctl_t *ctl, snd_ctl_element_list_t *list)
|
||||
{
|
||||
snd_ctl_shm_t *shm = ctl->private;
|
||||
volatile snd_ctl_shm_ctrl_t *ctrl = shm->ctrl;
|
||||
size_t maxsize = CTL_SHM_DATA_MAXLEN;
|
||||
size_t bytes = list->space * sizeof(*list->pids);
|
||||
int err;
|
||||
snd_control_id_t *pids = list->pids;
|
||||
snd_ctl_element_id_t *pids = list->pids;
|
||||
if (bytes > maxsize)
|
||||
return -EINVAL;
|
||||
ctrl->u.clist = *list;
|
||||
ctrl->cmd = SNDRV_CTL_IOCTL_CONTROL_LIST;
|
||||
ctrl->cmd = SNDRV_CTL_IOCTL_ELEMENT_LIST;
|
||||
err = snd_ctl_shm_action(ctl);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
|
@ -142,13 +142,13 @@ static int snd_ctl_shm_clist(snd_ctl_t *ctl, snd_control_list_t *list)
|
|||
return err;
|
||||
}
|
||||
|
||||
static int snd_ctl_shm_cinfo(snd_ctl_t *ctl, snd_control_info_t *info)
|
||||
static int snd_ctl_shm_cinfo(snd_ctl_t *ctl, snd_ctl_element_info_t *info)
|
||||
{
|
||||
snd_ctl_shm_t *shm = ctl->private;
|
||||
volatile snd_ctl_shm_ctrl_t *ctrl = shm->ctrl;
|
||||
int err;
|
||||
ctrl->u.cinfo = *info;
|
||||
ctrl->cmd = SNDRV_CTL_IOCTL_CONTROL_INFO;
|
||||
ctrl->cmd = SNDRV_CTL_IOCTL_ELEMENT_INFO;
|
||||
err = snd_ctl_shm_action(ctl);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
|
@ -156,13 +156,13 @@ static int snd_ctl_shm_cinfo(snd_ctl_t *ctl, snd_control_info_t *info)
|
|||
return err;
|
||||
}
|
||||
|
||||
static int snd_ctl_shm_cread(snd_ctl_t *ctl, snd_control_t *control)
|
||||
static int snd_ctl_shm_cread(snd_ctl_t *ctl, snd_ctl_element_t *control)
|
||||
{
|
||||
snd_ctl_shm_t *shm = ctl->private;
|
||||
volatile snd_ctl_shm_ctrl_t *ctrl = shm->ctrl;
|
||||
int err;
|
||||
ctrl->u.cread = *control;
|
||||
ctrl->cmd = SNDRV_CTL_IOCTL_CONTROL_READ;
|
||||
ctrl->cmd = SNDRV_CTL_IOCTL_ELEMENT_READ;
|
||||
err = snd_ctl_shm_action(ctl);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
|
@ -170,13 +170,13 @@ static int snd_ctl_shm_cread(snd_ctl_t *ctl, snd_control_t *control)
|
|||
return err;
|
||||
}
|
||||
|
||||
static int snd_ctl_shm_cwrite(snd_ctl_t *ctl, snd_control_t *control)
|
||||
static int snd_ctl_shm_cwrite(snd_ctl_t *ctl, snd_ctl_element_t *control)
|
||||
{
|
||||
snd_ctl_shm_t *shm = ctl->private;
|
||||
volatile snd_ctl_shm_ctrl_t *ctrl = shm->ctrl;
|
||||
int err;
|
||||
ctrl->u.cwrite = *control;
|
||||
ctrl->cmd = SNDRV_CTL_IOCTL_CONTROL_WRITE;
|
||||
ctrl->cmd = SNDRV_CTL_IOCTL_ELEMENT_WRITE;
|
||||
err = snd_ctl_shm_action(ctl);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
|
|
|||
|
|
@ -29,12 +29,12 @@
|
|||
#include <search.h>
|
||||
#include "control_local.h"
|
||||
|
||||
static void snd_ctl_hfree1(snd_hcontrol_t *hcontrol);
|
||||
static void snd_ctl_hfree1(snd_hctl_element_t *helem);
|
||||
|
||||
int snd_ctl_hbuild(snd_ctl_t *handle, snd_ctl_hsort_t hsort)
|
||||
{
|
||||
snd_control_list_t list;
|
||||
snd_hcontrol_t *hcontrol, *prev;
|
||||
snd_ctl_element_list_t list;
|
||||
snd_hctl_element_t *helem, *prev;
|
||||
int err;
|
||||
unsigned int idx;
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ int snd_ctl_hbuild(snd_ctl_t *handle, snd_ctl_hsort_t hsort)
|
|||
return err;
|
||||
if (list.count == 0)
|
||||
break;
|
||||
list.pids = (snd_control_id_t *)calloc(list.count, sizeof(snd_control_id_t));
|
||||
list.pids = (snd_ctl_element_id_t *)calloc(list.count, sizeof(snd_ctl_element_id_t));
|
||||
if (list.pids == NULL)
|
||||
return -ENOMEM;
|
||||
list.space = list.count;
|
||||
|
|
@ -61,24 +61,24 @@ int snd_ctl_hbuild(snd_ctl_t *handle, snd_ctl_hsort_t hsort)
|
|||
return err;
|
||||
} while (list.count != list.used);
|
||||
for (idx = 0, prev = NULL; idx < list.count; idx++) {
|
||||
hcontrol = (snd_hcontrol_t *)calloc(1, sizeof(snd_hcontrol_t));
|
||||
if (hcontrol == NULL)
|
||||
helem = (snd_hctl_element_t *)calloc(1, sizeof(snd_hctl_element_t));
|
||||
if (helem == NULL)
|
||||
goto __nomem;
|
||||
hcontrol->id = list.pids[idx];
|
||||
hcontrol->handle = handle;
|
||||
if (tsearch(hcontrol, &handle->hroot, (__compar_fn_t)hsort) == NULL) {
|
||||
helem->id = list.pids[idx];
|
||||
helem->handle = handle;
|
||||
if (tsearch(helem, &handle->hroot, (__compar_fn_t)hsort) == NULL) {
|
||||
__nomem:
|
||||
if (handle->hroot != NULL) {
|
||||
tdestroy(handle->hroot, (__free_fn_t)snd_ctl_hfree1);
|
||||
handle->hroot = NULL;
|
||||
}
|
||||
handle->hroot = NULL;
|
||||
if (hcontrol != NULL)
|
||||
free(hcontrol);
|
||||
if (helem != NULL)
|
||||
free(helem);
|
||||
free(list.pids);
|
||||
return -ENOMEM;
|
||||
}
|
||||
list_add_tail(&hcontrol->list, &handle->hlist);
|
||||
list_add_tail(&helem->list, &handle->hlist);
|
||||
handle->hcount++;
|
||||
}
|
||||
if (list.pids != NULL)
|
||||
|
|
@ -90,20 +90,20 @@ int snd_ctl_hbuild(snd_ctl_t *handle, snd_ctl_hsort_t hsort)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void snd_ctl_hfree1(snd_hcontrol_t *hcontrol)
|
||||
static void snd_ctl_hfree1(snd_hctl_element_t *helem)
|
||||
{
|
||||
snd_ctl_t *handle;
|
||||
|
||||
assert(hcontrol != NULL);
|
||||
handle = hcontrol->handle;
|
||||
assert(helem != NULL);
|
||||
handle = helem->handle;
|
||||
assert(handle != NULL);
|
||||
assert(handle->hcount > 0);
|
||||
if (hcontrol->callback_remove)
|
||||
hcontrol->callback_remove(handle, hcontrol);
|
||||
if (hcontrol->private_free)
|
||||
hcontrol->private_free(hcontrol);
|
||||
list_del(&hcontrol->list);
|
||||
free(hcontrol);
|
||||
if (helem->callback_remove)
|
||||
helem->callback_remove(handle, helem);
|
||||
if (helem->private_free)
|
||||
helem->private_free(helem);
|
||||
list_del(&helem->list);
|
||||
free(helem);
|
||||
handle->hcount--;
|
||||
}
|
||||
|
||||
|
|
@ -202,7 +202,7 @@ static int snd_ctl_hsort_mixer_priority(const char *name)
|
|||
return res + res1;
|
||||
}
|
||||
|
||||
int snd_ctl_hsort(const snd_hcontrol_t *c1, const snd_hcontrol_t *c2)
|
||||
int snd_ctl_hsort(const snd_hctl_element_t *c1, const snd_hctl_element_t *c2)
|
||||
{
|
||||
int res, p1, p2;
|
||||
|
||||
|
|
@ -211,7 +211,7 @@ int snd_ctl_hsort(const snd_hcontrol_t *c1, const snd_hcontrol_t *c2)
|
|||
if (c1->id.iface > c2->id.iface)
|
||||
return 1;
|
||||
if ((res = strcmp(c1->id.name, c2->id.name)) != 0) {
|
||||
if (c1->id.iface != SNDRV_CONTROL_IFACE_MIXER)
|
||||
if (c1->id.iface != SNDRV_CTL_ELEMENT_IFACE_MIXER)
|
||||
return res;
|
||||
p1 = snd_ctl_hsort_mixer_priority(c1->id.name);
|
||||
p2 = snd_ctl_hsort_mixer_priority(c2->id.name);
|
||||
|
|
@ -228,7 +228,7 @@ int snd_ctl_hsort(const snd_hcontrol_t *c1, const snd_hcontrol_t *c2)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void snd_ctl_hresort_free(snd_hcontrol_t *hcontrol ATTRIBUTE_UNUSED)
|
||||
static void snd_ctl_hresort_free(snd_hctl_element_t *helem ATTRIBUTE_UNUSED)
|
||||
{
|
||||
/* nothing */
|
||||
}
|
||||
|
|
@ -236,8 +236,8 @@ static void snd_ctl_hresort_free(snd_hcontrol_t *hcontrol ATTRIBUTE_UNUSED)
|
|||
int snd_ctl_hresort(snd_ctl_t *handle, snd_ctl_hsort_t hsort)
|
||||
{
|
||||
struct list_head *list;
|
||||
snd_hcontrol_t *hcontrol;
|
||||
snd_control_id_t *ids, *pids;
|
||||
snd_hctl_element_t *helem;
|
||||
snd_ctl_element_id_t *ids, *pids;
|
||||
int idx;
|
||||
|
||||
assert(handle != NULL && hsort != NULL);
|
||||
|
|
@ -246,14 +246,14 @@ int snd_ctl_hresort(snd_ctl_t *handle, snd_ctl_hsort_t hsort)
|
|||
if (handle->herr < 0)
|
||||
return handle->herr;
|
||||
assert(handle->hroot_new == NULL);
|
||||
ids = pids = (snd_control_id_t *)malloc(sizeof(snd_control_id_t) * handle->hcount);
|
||||
ids = pids = (snd_ctl_element_id_t *)malloc(sizeof(snd_ctl_element_id_t) * handle->hcount);
|
||||
if (ids == NULL)
|
||||
return -ENOMEM;
|
||||
/* first step - update search engine */
|
||||
list_for_each(list, &handle->hlist) {
|
||||
hcontrol = list_entry(list, snd_hcontrol_t, list);
|
||||
*pids++ = hcontrol->id;
|
||||
if (tsearch(hcontrol, &handle->hroot_new, (__compar_fn_t)hsort) == NULL) {
|
||||
helem = list_entry(list, snd_hctl_element_t, list);
|
||||
*pids++ = helem->id;
|
||||
if (tsearch(helem, &handle->hroot_new, (__compar_fn_t)hsort) == NULL) {
|
||||
if (handle->hroot_new != NULL)
|
||||
tdestroy(handle->hroot_new, (__free_fn_t)snd_ctl_hresort_free);
|
||||
handle->hroot_new = NULL;
|
||||
|
|
@ -267,46 +267,46 @@ int snd_ctl_hresort(snd_ctl_t *handle, snd_ctl_hsort_t hsort)
|
|||
handle->hroot = handle->hroot_new;
|
||||
handle->hroot_new = NULL;
|
||||
/* second step - perform qsort and save results */
|
||||
qsort(ids, handle->hcount, sizeof(snd_control_id_t), (int (*)(const void *, const void *))hsort);
|
||||
qsort(ids, handle->hcount, sizeof(snd_ctl_element_id_t), (int (*)(const void *, const void *))hsort);
|
||||
INIT_LIST_HEAD(&handle->hlist);
|
||||
for (idx = 0; idx < handle->hcount; idx++) {
|
||||
hcontrol = snd_ctl_hfind(handle, ids + idx);
|
||||
list_add_tail(&hcontrol->list, &handle->hlist);
|
||||
helem = snd_ctl_hfind(handle, ids + idx);
|
||||
list_add_tail(&helem->list, &handle->hlist);
|
||||
}
|
||||
free(ids);
|
||||
return 0;
|
||||
}
|
||||
|
||||
snd_hcontrol_t *snd_ctl_hfirst(snd_ctl_t *handle)
|
||||
snd_hctl_element_t *snd_ctl_hfirst(snd_ctl_t *handle)
|
||||
{
|
||||
assert(handle != NULL);
|
||||
if (list_empty(&handle->hlist))
|
||||
return NULL;
|
||||
return (snd_hcontrol_t *)list_entry(handle->hlist.next, snd_hcontrol_t, list);
|
||||
return (snd_hctl_element_t *)list_entry(handle->hlist.next, snd_hctl_element_t, list);
|
||||
}
|
||||
|
||||
snd_hcontrol_t *snd_ctl_hlast(snd_ctl_t *handle)
|
||||
snd_hctl_element_t *snd_ctl_hlast(snd_ctl_t *handle)
|
||||
{
|
||||
assert(handle != NULL);
|
||||
if (list_empty(&handle->hlist))
|
||||
return NULL;
|
||||
return (snd_hcontrol_t *)list_entry(handle->hlist.prev, snd_hcontrol_t, list);
|
||||
return (snd_hctl_element_t *)list_entry(handle->hlist.prev, snd_hctl_element_t, list);
|
||||
}
|
||||
|
||||
snd_hcontrol_t *snd_ctl_hnext(snd_ctl_t *handle, snd_hcontrol_t *hcontrol)
|
||||
snd_hctl_element_t *snd_ctl_hnext(snd_ctl_t *handle, snd_hctl_element_t *helem)
|
||||
{
|
||||
assert(handle != NULL && hcontrol != NULL);
|
||||
if (hcontrol->list.next == &handle->hlist)
|
||||
assert(handle != NULL && helem != NULL);
|
||||
if (helem->list.next == &handle->hlist)
|
||||
return NULL;
|
||||
return (snd_hcontrol_t *)list_entry(hcontrol->list.next, snd_hcontrol_t, list);
|
||||
return (snd_hctl_element_t *)list_entry(helem->list.next, snd_hctl_element_t, list);
|
||||
}
|
||||
|
||||
snd_hcontrol_t *snd_ctl_hprev(snd_ctl_t *handle, snd_hcontrol_t *hcontrol)
|
||||
snd_hctl_element_t *snd_ctl_hprev(snd_ctl_t *handle, snd_hctl_element_t *helem)
|
||||
{
|
||||
assert(handle != NULL && hcontrol != NULL);
|
||||
if (hcontrol->list.prev == &handle->hlist)
|
||||
assert(handle != NULL && helem != NULL);
|
||||
if (helem->list.prev == &handle->hlist)
|
||||
return NULL;
|
||||
return (snd_hcontrol_t *)list_entry(hcontrol->list.prev, snd_hcontrol_t, list);
|
||||
return (snd_hctl_element_t *)list_entry(helem->list.prev, snd_hctl_element_t, list);
|
||||
}
|
||||
|
||||
int snd_ctl_hcount(snd_ctl_t *handle)
|
||||
|
|
@ -315,7 +315,7 @@ int snd_ctl_hcount(snd_ctl_t *handle)
|
|||
return handle->hcount;
|
||||
}
|
||||
|
||||
snd_hcontrol_t *snd_ctl_hfind(snd_ctl_t *handle, snd_control_id_t *id)
|
||||
snd_hctl_element_t *snd_ctl_hfind(snd_ctl_t *handle, snd_ctl_element_id_t *id)
|
||||
{
|
||||
void *res;
|
||||
|
||||
|
|
@ -323,13 +323,13 @@ snd_hcontrol_t *snd_ctl_hfind(snd_ctl_t *handle, snd_control_id_t *id)
|
|||
if (handle->hroot == NULL)
|
||||
return NULL;
|
||||
res = tfind(id, &handle->hroot, (__compar_fn_t)handle->hsort);
|
||||
return res == NULL ? NULL : *(snd_hcontrol_t **)res;
|
||||
return res == NULL ? NULL : *(snd_hctl_element_t **)res;
|
||||
}
|
||||
|
||||
int snd_ctl_hlist(snd_ctl_t *handle, snd_hcontrol_list_t *hlist)
|
||||
int snd_ctl_hlist(snd_ctl_t *handle, snd_hctl_element_list_t *hlist)
|
||||
{
|
||||
struct list_head *list;
|
||||
snd_hcontrol_t *hcontrol;
|
||||
snd_hctl_element_t *helem;
|
||||
unsigned int idx;
|
||||
|
||||
assert(hlist != NULL);
|
||||
|
|
@ -342,11 +342,11 @@ int snd_ctl_hlist(snd_ctl_t *handle, snd_hcontrol_list_t *hlist)
|
|||
return -EINVAL;
|
||||
idx = 0;
|
||||
list_for_each(list, &handle->hlist) {
|
||||
hcontrol = list_entry(list, snd_hcontrol_t, list);
|
||||
helem = list_entry(list, snd_hctl_element_t, list);
|
||||
if (idx >= hlist->offset + hlist->space)
|
||||
break;
|
||||
if (idx >= hlist->offset) {
|
||||
hlist->pids[idx] = hcontrol->id;
|
||||
hlist->pids[idx] = helem->id;
|
||||
hlist->used++;
|
||||
}
|
||||
idx++;
|
||||
|
|
@ -378,75 +378,75 @@ static void callback_rebuild(snd_ctl_t *handle, void *private_data ATTRIBUTE_UNU
|
|||
handle->callback_rebuild(handle, handle->callback_rebuild_private_data);
|
||||
}
|
||||
|
||||
static void callback_change(snd_ctl_t *handle, void *private_data ATTRIBUTE_UNUSED, snd_control_id_t *id)
|
||||
static void callback_change(snd_ctl_t *handle, void *private_data ATTRIBUTE_UNUSED, snd_ctl_element_id_t *id)
|
||||
{
|
||||
snd_hcontrol_t *hcontrol;
|
||||
snd_hctl_element_t *helem;
|
||||
|
||||
if (handle->herr < 0)
|
||||
return;
|
||||
hcontrol = snd_ctl_hfind(handle, id);
|
||||
if (hcontrol == NULL) {
|
||||
helem = snd_ctl_hfind(handle, id);
|
||||
if (helem == NULL) {
|
||||
handle->herr = -ENOENT;
|
||||
return;
|
||||
}
|
||||
hcontrol->change = 1;
|
||||
helem->change = 1;
|
||||
}
|
||||
|
||||
static void callback_value(snd_ctl_t *handle, void *private_data ATTRIBUTE_UNUSED, snd_control_id_t *id)
|
||||
static void callback_value(snd_ctl_t *handle, void *private_data ATTRIBUTE_UNUSED, snd_ctl_element_id_t *id)
|
||||
{
|
||||
snd_hcontrol_t *hcontrol;
|
||||
snd_hctl_element_t *helem;
|
||||
|
||||
if (handle->herr < 0)
|
||||
return;
|
||||
hcontrol = snd_ctl_hfind(handle, id);
|
||||
if (hcontrol == NULL) {
|
||||
helem = snd_ctl_hfind(handle, id);
|
||||
if (helem == NULL) {
|
||||
handle->herr = -ENOENT;
|
||||
return;
|
||||
}
|
||||
hcontrol->value = 1;
|
||||
helem->value = 1;
|
||||
}
|
||||
|
||||
static void callback_add(snd_ctl_t *handle, void *private_data ATTRIBUTE_UNUSED, snd_control_id_t *id)
|
||||
static void callback_add(snd_ctl_t *handle, void *private_data ATTRIBUTE_UNUSED, snd_ctl_element_id_t *id)
|
||||
{
|
||||
snd_hcontrol_t *hcontrol, *icontrol;
|
||||
snd_hctl_element_t *helem, *icontrol;
|
||||
|
||||
if (handle->herr < 0)
|
||||
return;
|
||||
hcontrol = (snd_hcontrol_t *)calloc(1, sizeof(snd_hcontrol_t));
|
||||
if (hcontrol == NULL) {
|
||||
helem = (snd_hctl_element_t *)calloc(1, sizeof(snd_hctl_element_t));
|
||||
if (helem == NULL) {
|
||||
handle->herr = -ENOMEM;
|
||||
return;
|
||||
}
|
||||
hcontrol->id = *id;
|
||||
hcontrol->handle = handle;
|
||||
icontrol = tsearch(hcontrol, &handle->hroot, (__compar_fn_t)handle->hsort);
|
||||
helem->id = *id;
|
||||
helem->handle = handle;
|
||||
icontrol = tsearch(helem, &handle->hroot, (__compar_fn_t)handle->hsort);
|
||||
if (icontrol == NULL) {
|
||||
free(hcontrol);
|
||||
free(helem);
|
||||
handle->herr = -ENOMEM;
|
||||
return;
|
||||
}
|
||||
if (icontrol != hcontrol) { /* double hit */
|
||||
free(hcontrol);
|
||||
if (icontrol != helem) { /* double hit */
|
||||
free(helem);
|
||||
return;
|
||||
}
|
||||
list_add_tail(&hcontrol->list, &handle->hlist);
|
||||
list_add_tail(&helem->list, &handle->hlist);
|
||||
if (handle->callback_add)
|
||||
handle->callback_add(handle, handle->callback_add_private_data, hcontrol);
|
||||
handle->callback_add(handle, handle->callback_add_private_data, helem);
|
||||
}
|
||||
|
||||
static void callback_remove(snd_ctl_t *handle, void *private_data ATTRIBUTE_UNUSED, snd_control_id_t *id)
|
||||
static void callback_remove(snd_ctl_t *handle, void *private_data ATTRIBUTE_UNUSED, snd_ctl_element_id_t *id)
|
||||
{
|
||||
snd_hcontrol_t *hcontrol;
|
||||
snd_hctl_element_t *helem;
|
||||
|
||||
if (handle->herr < 0)
|
||||
return;
|
||||
hcontrol = snd_ctl_hfind(handle, id);
|
||||
if (hcontrol == NULL) {
|
||||
helem = snd_ctl_hfind(handle, id);
|
||||
if (helem == NULL) {
|
||||
handle->herr = -ENOENT;
|
||||
return;
|
||||
}
|
||||
if (tdelete(hcontrol, &handle->hroot, (__compar_fn_t)handle->hsort) != NULL)
|
||||
snd_ctl_hfree1(hcontrol);
|
||||
if (tdelete(helem, &handle->hroot, (__compar_fn_t)handle->hsort) != NULL)
|
||||
snd_ctl_hfree1(helem);
|
||||
}
|
||||
|
||||
int snd_ctl_hevent(snd_ctl_t *handle)
|
||||
|
|
@ -461,7 +461,7 @@ int snd_ctl_hevent(snd_ctl_t *handle)
|
|||
reserved: { NULL, }
|
||||
};
|
||||
struct list_head *list;
|
||||
snd_hcontrol_t *hcontrol;
|
||||
snd_hctl_element_t *helem;
|
||||
int res;
|
||||
|
||||
assert(handle != NULL);
|
||||
|
|
@ -472,20 +472,20 @@ int snd_ctl_hevent(snd_ctl_t *handle)
|
|||
if (handle->herr < 0)
|
||||
return handle->herr;
|
||||
list_for_each(list, &handle->hlist) {
|
||||
hcontrol = list_entry(list, snd_hcontrol_t, list);
|
||||
if (hcontrol->change && hcontrol->callback_change) {
|
||||
hcontrol->callback_change(hcontrol->handle, hcontrol);
|
||||
hcontrol->change = 0;
|
||||
helem = list_entry(list, snd_hctl_element_t, list);
|
||||
if (helem->change && helem->callback_change) {
|
||||
helem->callback_change(helem->handle, helem);
|
||||
helem->change = 0;
|
||||
}
|
||||
if (hcontrol->value && hcontrol->callback_value) {
|
||||
hcontrol->callback_value(hcontrol->handle, hcontrol);
|
||||
hcontrol->value = 0;
|
||||
if (helem->value && helem->callback_value) {
|
||||
helem->callback_value(helem->handle, helem);
|
||||
helem->value = 0;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
int snd_hcontrol_list_alloc_space(snd_hcontrol_list_t *obj, unsigned int entries)
|
||||
int snd_hctl_element_list_alloc_space(snd_hctl_element_list_t *obj, unsigned int entries)
|
||||
{
|
||||
obj->pids = calloc(entries, sizeof(*obj->pids));
|
||||
if (!obj->pids) {
|
||||
|
|
@ -496,7 +496,7 @@ int snd_hcontrol_list_alloc_space(snd_hcontrol_list_t *obj, unsigned int entries
|
|||
return 0;
|
||||
}
|
||||
|
||||
void snd_hcontrol_list_free_space(snd_hcontrol_list_t *obj)
|
||||
void snd_hctl_element_list_free_space(snd_hctl_element_list_t *obj)
|
||||
{
|
||||
free(obj->pids);
|
||||
obj->pids = NULL;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue