mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-11-04 13:30:08 -05:00
Completed mixer API. Improved iterators. Renamed control values struct. Rewritten simple elements implementation
This commit is contained in:
parent
38033b49dd
commit
a2d3434961
54 changed files with 2081 additions and 1712 deletions
|
|
@ -29,16 +29,24 @@
|
|||
#include <sys/poll.h>
|
||||
#include "control_local.h"
|
||||
|
||||
const char *snd_ctl_name(snd_ctl_t *ctl)
|
||||
{
|
||||
assert(ctl);
|
||||
return ctl->name;
|
||||
}
|
||||
|
||||
snd_ctl_type_t snd_ctl_type(snd_ctl_t *ctl)
|
||||
{
|
||||
assert(ctl);
|
||||
return ctl->type;
|
||||
}
|
||||
|
||||
int snd_ctl_close(snd_ctl_t *ctl)
|
||||
{
|
||||
int res;
|
||||
assert(ctl);
|
||||
res = ctl->ops->close(ctl);
|
||||
if (ctl->name)
|
||||
free(ctl->name);
|
||||
free(ctl);
|
||||
return res;
|
||||
}
|
||||
|
|
@ -85,13 +93,13 @@ int snd_ctl_elem_info(snd_ctl_t *ctl, snd_ctl_elem_info_t *info)
|
|||
return ctl->ops->element_info(ctl, info);
|
||||
}
|
||||
|
||||
int snd_ctl_elem_read(snd_ctl_t *ctl, snd_ctl_elem_t *control)
|
||||
int snd_ctl_elem_read(snd_ctl_t *ctl, snd_ctl_elem_value_t *control)
|
||||
{
|
||||
assert(ctl && control && (control->id.name[0] || control->id.numid));
|
||||
return ctl->ops->element_read(ctl, control);
|
||||
}
|
||||
|
||||
int snd_ctl_elem_write(snd_ctl_t *ctl, snd_ctl_elem_t *control)
|
||||
int snd_ctl_elem_write(snd_ctl_t *ctl, snd_ctl_elem_value_t *control)
|
||||
{
|
||||
assert(ctl && control && (control->id.name[0] || control->id.numid));
|
||||
return ctl->ops->element_write(ctl, control);
|
||||
|
|
@ -163,14 +171,14 @@ int snd_ctl_wait(snd_ctl_t *ctl, int timeout)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int snd_ctl_open(snd_ctl_t **ctlp, char *name)
|
||||
int snd_ctl_open(snd_ctl_t **ctlp, const char *name)
|
||||
{
|
||||
const char *str;
|
||||
int err;
|
||||
snd_config_t *ctl_conf, *conf, *type_conf;
|
||||
snd_config_iterator_t i;
|
||||
snd_config_iterator_t i, next;
|
||||
const char *lib = NULL, *open = NULL;
|
||||
int (*open_func)(snd_ctl_t **ctlp, char *name, snd_config_t *conf);
|
||||
int (*open_func)(snd_ctl_t **ctlp, const char *name, snd_config_t *conf);
|
||||
void *h;
|
||||
assert(ctlp && name);
|
||||
err = snd_config_update();
|
||||
|
|
@ -182,10 +190,10 @@ int snd_ctl_open(snd_ctl_t **ctlp, char *name)
|
|||
char socket[256], sname[256];
|
||||
err = sscanf(name, "hw:%d", &card);
|
||||
if (err == 1)
|
||||
return snd_ctl_hw_open(ctlp, NULL, card);
|
||||
return snd_ctl_hw_open(ctlp, name, card);
|
||||
err = sscanf(name, "shm:%256[^,],%256[^,]", socket, sname);
|
||||
if (err == 2)
|
||||
return snd_ctl_shm_open(ctlp, NULL, socket, sname);
|
||||
return snd_ctl_shm_open(ctlp, name, socket, sname);
|
||||
ERR("Unknown control %s", name);
|
||||
return -ENOENT;
|
||||
}
|
||||
|
|
@ -198,7 +206,7 @@ int snd_ctl_open(snd_ctl_t **ctlp, char *name)
|
|||
if (err < 0)
|
||||
return err;
|
||||
err = snd_config_searchv(snd_config, &type_conf, "ctltype", str, 0);
|
||||
snd_config_foreach(i, type_conf) {
|
||||
snd_config_for_each(i, next, type_conf) {
|
||||
snd_config_t *n = snd_config_iterator_entry(i);
|
||||
const char *id = snd_config_get_id(n);
|
||||
if (strcmp(id, "comment") == 0)
|
||||
|
|
@ -231,7 +239,7 @@ int snd_ctl_open(snd_ctl_t **ctlp, char *name)
|
|||
return open_func(ctlp, name, ctl_conf);
|
||||
}
|
||||
|
||||
void snd_ctl_elem_set_bytes(snd_ctl_elem_t *obj, void *data, size_t size)
|
||||
void snd_ctl_elem_set_bytes(snd_ctl_elem_value_t *obj, void *data, size_t size)
|
||||
{
|
||||
assert(obj);
|
||||
assert(size <= sizeof(obj->value.bytes.data));
|
||||
|
|
@ -264,7 +272,7 @@ const char *snd_ctl_elem_iface_names[] = {
|
|||
const char *snd_ctl_event_type_names[] = {
|
||||
EVENT(REBUILD),
|
||||
EVENT(VALUE),
|
||||
EVENT(CHANGE),
|
||||
EVENT(INFO),
|
||||
EVENT(ADD),
|
||||
EVENT(REMOVE),
|
||||
};
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ typedef struct {
|
|||
|
||||
static int snd_ctl_hw_close(snd_ctl_t *handle)
|
||||
{
|
||||
snd_ctl_hw_t *hw = handle->private;
|
||||
snd_ctl_hw_t *hw = handle->private_data;
|
||||
int res;
|
||||
res = close(hw->fd) < 0 ? -errno : 0;
|
||||
free(hw);
|
||||
|
|
@ -52,7 +52,7 @@ static int snd_ctl_hw_close(snd_ctl_t *handle)
|
|||
|
||||
static int snd_ctl_hw_nonblock(snd_ctl_t *handle, int nonblock)
|
||||
{
|
||||
snd_ctl_hw_t *hw = handle->private;
|
||||
snd_ctl_hw_t *hw = handle->private_data;
|
||||
long flags;
|
||||
int fd = hw->fd;
|
||||
if ((flags = fcntl(fd, F_GETFL)) < 0) {
|
||||
|
|
@ -73,7 +73,7 @@ static int snd_ctl_hw_nonblock(snd_ctl_t *handle, int nonblock)
|
|||
static int snd_ctl_hw_async(snd_ctl_t *ctl, int sig, pid_t pid)
|
||||
{
|
||||
long flags;
|
||||
snd_ctl_hw_t *hw = ctl->private;
|
||||
snd_ctl_hw_t *hw = ctl->private_data;
|
||||
int fd = hw->fd;
|
||||
|
||||
if ((flags = fcntl(fd, F_GETFL)) < 0) {
|
||||
|
|
@ -107,13 +107,13 @@ static int snd_ctl_hw_async(snd_ctl_t *ctl, int sig, pid_t pid)
|
|||
|
||||
static int snd_ctl_hw_poll_descriptor(snd_ctl_t *handle)
|
||||
{
|
||||
snd_ctl_hw_t *hw = handle->private;
|
||||
snd_ctl_hw_t *hw = handle->private_data;
|
||||
return hw->fd;
|
||||
}
|
||||
|
||||
static int snd_ctl_hw_hw_info(snd_ctl_t *handle, snd_ctl_card_info_t *info)
|
||||
{
|
||||
snd_ctl_hw_t *hw = handle->private;
|
||||
snd_ctl_hw_t *hw = handle->private_data;
|
||||
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_INFO, info) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
|
|
@ -121,7 +121,7 @@ static int snd_ctl_hw_hw_info(snd_ctl_t *handle, snd_ctl_card_info_t *info)
|
|||
|
||||
static int snd_ctl_hw_elem_list(snd_ctl_t *handle, snd_ctl_elem_list_t *list)
|
||||
{
|
||||
snd_ctl_hw_t *hw = handle->private;
|
||||
snd_ctl_hw_t *hw = handle->private_data;
|
||||
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_ELEM_LIST, list) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
|
|
@ -129,23 +129,23 @@ static int snd_ctl_hw_elem_list(snd_ctl_t *handle, snd_ctl_elem_list_t *list)
|
|||
|
||||
static int snd_ctl_hw_elem_info(snd_ctl_t *handle, snd_ctl_elem_info_t *info)
|
||||
{
|
||||
snd_ctl_hw_t *hw = handle->private;
|
||||
snd_ctl_hw_t *hw = handle->private_data;
|
||||
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_ELEM_INFO, info) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int snd_ctl_hw_elem_read(snd_ctl_t *handle, snd_ctl_elem_t *control)
|
||||
static int snd_ctl_hw_elem_read(snd_ctl_t *handle, snd_ctl_elem_value_t *control)
|
||||
{
|
||||
snd_ctl_hw_t *hw = handle->private;
|
||||
snd_ctl_hw_t *hw = handle->private_data;
|
||||
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_ELEM_READ, control) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int snd_ctl_hw_elem_write(snd_ctl_t *handle, snd_ctl_elem_t *control)
|
||||
static int snd_ctl_hw_elem_write(snd_ctl_t *handle, snd_ctl_elem_value_t *control)
|
||||
{
|
||||
snd_ctl_hw_t *hw = handle->private;
|
||||
snd_ctl_hw_t *hw = handle->private_data;
|
||||
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_ELEM_WRITE, control) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
|
|
@ -153,7 +153,7 @@ static int snd_ctl_hw_elem_write(snd_ctl_t *handle, snd_ctl_elem_t *control)
|
|||
|
||||
static int snd_ctl_hw_hwdep_next_device(snd_ctl_t *handle, int * device)
|
||||
{
|
||||
snd_ctl_hw_t *hw = handle->private;
|
||||
snd_ctl_hw_t *hw = handle->private_data;
|
||||
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_HWDEP_NEXT_DEVICE, device) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
|
|
@ -161,7 +161,7 @@ static int snd_ctl_hw_hwdep_next_device(snd_ctl_t *handle, int * device)
|
|||
|
||||
static int snd_ctl_hw_hwdep_info(snd_ctl_t *handle, snd_hwdep_info_t * info)
|
||||
{
|
||||
snd_ctl_hw_t *hw = handle->private;
|
||||
snd_ctl_hw_t *hw = handle->private_data;
|
||||
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_HWDEP_INFO, info) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
|
|
@ -169,7 +169,7 @@ static int snd_ctl_hw_hwdep_info(snd_ctl_t *handle, snd_hwdep_info_t * info)
|
|||
|
||||
static int snd_ctl_hw_pcm_next_device(snd_ctl_t *handle, int * device)
|
||||
{
|
||||
snd_ctl_hw_t *hw = handle->private;
|
||||
snd_ctl_hw_t *hw = handle->private_data;
|
||||
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_PCM_NEXT_DEVICE, device) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
|
|
@ -177,7 +177,7 @@ static int snd_ctl_hw_pcm_next_device(snd_ctl_t *handle, int * device)
|
|||
|
||||
static int snd_ctl_hw_pcm_info(snd_ctl_t *handle, snd_pcm_info_t * info)
|
||||
{
|
||||
snd_ctl_hw_t *hw = handle->private;
|
||||
snd_ctl_hw_t *hw = handle->private_data;
|
||||
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_PCM_INFO, info) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
|
|
@ -185,7 +185,7 @@ static int snd_ctl_hw_pcm_info(snd_ctl_t *handle, snd_pcm_info_t * info)
|
|||
|
||||
static int snd_ctl_hw_pcm_prefer_subdevice(snd_ctl_t *handle, int subdev)
|
||||
{
|
||||
snd_ctl_hw_t *hw = handle->private;
|
||||
snd_ctl_hw_t *hw = handle->private_data;
|
||||
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_PCM_PREFER_SUBDEVICE, &subdev) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
|
|
@ -193,7 +193,7 @@ static int snd_ctl_hw_pcm_prefer_subdevice(snd_ctl_t *handle, int subdev)
|
|||
|
||||
static int snd_ctl_hw_rawmidi_next_device(snd_ctl_t *handle, int * device)
|
||||
{
|
||||
snd_ctl_hw_t *hw = handle->private;
|
||||
snd_ctl_hw_t *hw = handle->private_data;
|
||||
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_RAWMIDI_NEXT_DEVICE, device) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
|
|
@ -201,7 +201,7 @@ static int snd_ctl_hw_rawmidi_next_device(snd_ctl_t *handle, int * device)
|
|||
|
||||
static int snd_ctl_hw_rawmidi_info(snd_ctl_t *handle, snd_rawmidi_info_t * info)
|
||||
{
|
||||
snd_ctl_hw_t *hw = handle->private;
|
||||
snd_ctl_hw_t *hw = handle->private_data;
|
||||
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_RAWMIDI_INFO, info) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
|
|
@ -209,7 +209,7 @@ static int snd_ctl_hw_rawmidi_info(snd_ctl_t *handle, snd_rawmidi_info_t * info)
|
|||
|
||||
static int snd_ctl_hw_rawmidi_prefer_subdevice(snd_ctl_t *handle, int subdev)
|
||||
{
|
||||
snd_ctl_hw_t *hw = handle->private;
|
||||
snd_ctl_hw_t *hw = handle->private_data;
|
||||
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_RAWMIDI_PREFER_SUBDEVICE, &subdev) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
|
|
@ -217,7 +217,7 @@ static int snd_ctl_hw_rawmidi_prefer_subdevice(snd_ctl_t *handle, int subdev)
|
|||
|
||||
static int snd_ctl_hw_read(snd_ctl_t *handle, snd_ctl_event_t *event)
|
||||
{
|
||||
snd_ctl_hw_t *hw = handle->private;
|
||||
snd_ctl_hw_t *hw = handle->private_data;
|
||||
ssize_t res = read(hw->fd, event, sizeof(*event));
|
||||
if (res <= 0)
|
||||
return res;
|
||||
|
|
@ -288,18 +288,18 @@ int snd_ctl_hw_open(snd_ctl_t **handle, const char *name, int card)
|
|||
ctl->name = strdup(name);
|
||||
ctl->type = SND_CTL_TYPE_HW;
|
||||
ctl->ops = &snd_ctl_hw_ops;
|
||||
ctl->private = hw;
|
||||
ctl->private_data = hw;
|
||||
*handle = ctl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _snd_ctl_hw_open(snd_ctl_t **handlep, char *name, snd_config_t *conf)
|
||||
{
|
||||
snd_config_iterator_t i;
|
||||
snd_config_iterator_t i, next;
|
||||
long card = -1;
|
||||
const char *str;
|
||||
int err;
|
||||
snd_config_foreach(i, conf) {
|
||||
snd_config_for_each(i, next, conf) {
|
||||
snd_config_t *n = snd_config_iterator_entry(i);
|
||||
const char *id = snd_config_get_id(n);
|
||||
if (strcmp(id, "comment") == 0)
|
||||
|
|
|
|||
|
|
@ -30,8 +30,8 @@ typedef struct _snd_ctl_ops {
|
|||
int (*hw_info)(snd_ctl_t *handle, snd_ctl_card_info_t *info);
|
||||
int (*element_list)(snd_ctl_t *handle, snd_ctl_elem_list_t *list);
|
||||
int (*element_info)(snd_ctl_t *handle, snd_ctl_elem_info_t *info);
|
||||
int (*element_read)(snd_ctl_t *handle, snd_ctl_elem_t *control);
|
||||
int (*element_write)(snd_ctl_t *handle, snd_ctl_elem_t *control);
|
||||
int (*element_read)(snd_ctl_t *handle, snd_ctl_elem_value_t *control);
|
||||
int (*element_write)(snd_ctl_t *handle, snd_ctl_elem_value_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);
|
||||
|
|
@ -48,7 +48,7 @@ struct _snd_ctl {
|
|||
char *name;
|
||||
snd_ctl_type_t type;
|
||||
snd_ctl_ops_t *ops;
|
||||
void *private;
|
||||
void *private_data;
|
||||
int nonblock;
|
||||
};
|
||||
|
||||
|
|
@ -64,11 +64,11 @@ struct _snd_hctl_elem {
|
|||
|
||||
struct _snd_hctl {
|
||||
snd_ctl_t *ctl;
|
||||
struct list_head hlist; /* list of all controls */
|
||||
unsigned int halloc;
|
||||
unsigned int hcount;
|
||||
snd_hctl_elem_t **helems;
|
||||
snd_hctl_compare_t hcompare;
|
||||
struct list_head elems; /* list of all controls */
|
||||
unsigned int alloc;
|
||||
unsigned int count;
|
||||
snd_hctl_elem_t **pelems;
|
||||
snd_hctl_compare_t compare;
|
||||
snd_hctl_callback_t callback;
|
||||
void *callback_private;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -561,210 +561,185 @@ void snd_ctl_elem_info_set_index(snd_ctl_elem_info_t *obj, unsigned int val)
|
|||
obj->id.index = val;
|
||||
}
|
||||
|
||||
size_t snd_ctl_elem_sizeof()
|
||||
size_t snd_ctl_elem_value_sizeof()
|
||||
{
|
||||
return sizeof(snd_ctl_elem_t);
|
||||
return sizeof(snd_ctl_elem_value_t);
|
||||
}
|
||||
|
||||
int snd_ctl_elem_malloc(snd_ctl_elem_t **ptr)
|
||||
int snd_ctl_elem_value_malloc(snd_ctl_elem_value_t **ptr)
|
||||
{
|
||||
assert(ptr);
|
||||
*ptr = calloc(1, sizeof(snd_ctl_elem_t));
|
||||
*ptr = calloc(1, sizeof(snd_ctl_elem_value_t));
|
||||
if (!*ptr)
|
||||
return -ENOMEM;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void snd_ctl_elem_free(snd_ctl_elem_t *obj)
|
||||
void snd_ctl_elem_value_free(snd_ctl_elem_value_t *obj)
|
||||
{
|
||||
free(obj);
|
||||
}
|
||||
|
||||
void snd_ctl_elem_copy(snd_ctl_elem_t *dst, const snd_ctl_elem_t *src)
|
||||
void snd_ctl_elem_value_copy(snd_ctl_elem_value_t *dst, const snd_ctl_elem_value_t *src)
|
||||
{
|
||||
assert(dst && src);
|
||||
*dst = *src;
|
||||
}
|
||||
|
||||
void snd_ctl_elem_get_id(const snd_ctl_elem_t *obj, snd_ctl_elem_id_t *ptr)
|
||||
void snd_ctl_elem_value_get_id(const snd_ctl_elem_value_t *obj, snd_ctl_elem_id_t *ptr)
|
||||
{
|
||||
assert(obj && ptr);
|
||||
*ptr = obj->id;
|
||||
}
|
||||
|
||||
unsigned int snd_ctl_elem_get_numid(const snd_ctl_elem_t *obj)
|
||||
unsigned int snd_ctl_elem_value_get_numid(const snd_ctl_elem_value_t *obj)
|
||||
{
|
||||
assert(obj);
|
||||
return obj->id.numid;
|
||||
}
|
||||
|
||||
snd_ctl_elem_iface_t snd_ctl_elem_get_interface(const snd_ctl_elem_t *obj)
|
||||
snd_ctl_elem_iface_t snd_ctl_elem_value_get_interface(const snd_ctl_elem_value_t *obj)
|
||||
{
|
||||
assert(obj);
|
||||
return snd_int_to_enum(obj->id.iface);
|
||||
}
|
||||
|
||||
unsigned int snd_ctl_elem_get_device(const snd_ctl_elem_t *obj)
|
||||
unsigned int snd_ctl_elem_value_get_device(const snd_ctl_elem_value_t *obj)
|
||||
{
|
||||
assert(obj);
|
||||
return obj->id.device;
|
||||
}
|
||||
|
||||
unsigned int snd_ctl_elem_get_subdevice(const snd_ctl_elem_t *obj)
|
||||
unsigned int snd_ctl_elem_value_get_subdevice(const snd_ctl_elem_value_t *obj)
|
||||
{
|
||||
assert(obj);
|
||||
return obj->id.subdevice;
|
||||
}
|
||||
|
||||
const char *snd_ctl_elem_get_name(const snd_ctl_elem_t *obj)
|
||||
const char *snd_ctl_elem_value_get_name(const snd_ctl_elem_value_t *obj)
|
||||
{
|
||||
assert(obj);
|
||||
return obj->id.name;
|
||||
}
|
||||
|
||||
unsigned int snd_ctl_elem_get_index(const snd_ctl_elem_t *obj)
|
||||
unsigned int snd_ctl_elem_value_get_index(const snd_ctl_elem_value_t *obj)
|
||||
{
|
||||
assert(obj);
|
||||
return obj->id.index;
|
||||
}
|
||||
|
||||
void snd_ctl_elem_set_id(snd_ctl_elem_t *obj, const snd_ctl_elem_id_t *ptr)
|
||||
void snd_ctl_elem_value_set_id(snd_ctl_elem_value_t *obj, const snd_ctl_elem_id_t *ptr)
|
||||
{
|
||||
assert(obj && ptr);
|
||||
obj->id = *ptr;
|
||||
}
|
||||
|
||||
void snd_ctl_elem_set_numid(snd_ctl_elem_t *obj, unsigned int val)
|
||||
void snd_ctl_elem_value_set_numid(snd_ctl_elem_value_t *obj, unsigned int val)
|
||||
{
|
||||
assert(obj);
|
||||
obj->id.numid = val;
|
||||
}
|
||||
|
||||
void snd_ctl_elem_set_interface(snd_ctl_elem_t *obj, snd_ctl_elem_iface_t val)
|
||||
void snd_ctl_elem_value_set_interface(snd_ctl_elem_value_t *obj, snd_ctl_elem_iface_t val)
|
||||
{
|
||||
assert(obj);
|
||||
obj->id.iface = snd_enum_to_int(val);
|
||||
}
|
||||
|
||||
void snd_ctl_elem_set_device(snd_ctl_elem_t *obj, unsigned int val)
|
||||
void snd_ctl_elem_value_set_device(snd_ctl_elem_value_t *obj, unsigned int val)
|
||||
{
|
||||
assert(obj);
|
||||
obj->id.device = val;
|
||||
}
|
||||
|
||||
void snd_ctl_elem_set_subdevice(snd_ctl_elem_t *obj, unsigned int val)
|
||||
void snd_ctl_elem_value_set_subdevice(snd_ctl_elem_value_t *obj, unsigned int val)
|
||||
{
|
||||
assert(obj);
|
||||
obj->id.subdevice = val;
|
||||
}
|
||||
|
||||
void snd_ctl_elem_set_name(snd_ctl_elem_t *obj, const char *val)
|
||||
void snd_ctl_elem_value_set_name(snd_ctl_elem_value_t *obj, const char *val)
|
||||
{
|
||||
assert(obj);
|
||||
strncpy(obj->id.name, val, sizeof(obj->id.name));
|
||||
}
|
||||
|
||||
void snd_ctl_elem_set_index(snd_ctl_elem_t *obj, unsigned int val)
|
||||
void snd_ctl_elem_value_set_index(snd_ctl_elem_value_t *obj, unsigned int val)
|
||||
{
|
||||
assert(obj);
|
||||
obj->id.index = val;
|
||||
}
|
||||
|
||||
long snd_ctl_elem_get_boolean(const snd_ctl_elem_t *obj, unsigned int idx)
|
||||
long snd_ctl_elem_value_get_boolean(const snd_ctl_elem_value_t *obj, unsigned int idx)
|
||||
{
|
||||
assert(obj);
|
||||
assert(idx < sizeof(obj->value.integer.value) / sizeof(obj->value.integer.value[0]));
|
||||
return obj->value.integer.value[idx];
|
||||
}
|
||||
|
||||
long snd_ctl_elem_get_integer(const snd_ctl_elem_t *obj, unsigned int idx)
|
||||
long snd_ctl_elem_value_get_integer(const snd_ctl_elem_value_t *obj, unsigned int idx)
|
||||
{
|
||||
assert(obj);
|
||||
assert(idx < sizeof(obj->value.integer.value) / sizeof(obj->value.integer.value[0]));
|
||||
return obj->value.integer.value[idx];
|
||||
}
|
||||
|
||||
unsigned int snd_ctl_elem_get_enumerated(const snd_ctl_elem_t *obj, unsigned int idx)
|
||||
unsigned int snd_ctl_elem_value_get_enumerated(const snd_ctl_elem_value_t *obj, unsigned int idx)
|
||||
{
|
||||
assert(obj);
|
||||
assert(idx < sizeof(obj->value.enumerated.item) / sizeof(obj->value.enumerated.item[0]));
|
||||
return obj->value.enumerated.item[idx];
|
||||
}
|
||||
|
||||
unsigned char snd_ctl_elem_get_byte(const snd_ctl_elem_t *obj, unsigned int idx)
|
||||
unsigned char snd_ctl_elem_value_get_byte(const snd_ctl_elem_value_t *obj, unsigned int idx)
|
||||
{
|
||||
assert(obj);
|
||||
assert(idx < sizeof(obj->value.bytes.data));
|
||||
return obj->value.bytes.data[idx];
|
||||
}
|
||||
|
||||
void snd_ctl_elem_set_boolean(snd_ctl_elem_t *obj, unsigned int idx, long val)
|
||||
void snd_ctl_elem_value_set_boolean(snd_ctl_elem_value_t *obj, unsigned int idx, long val)
|
||||
{
|
||||
assert(obj);
|
||||
obj->value.integer.value[idx] = val;
|
||||
}
|
||||
|
||||
void snd_ctl_elem_set_integer(snd_ctl_elem_t *obj, unsigned int idx, long val)
|
||||
void snd_ctl_elem_value_set_integer(snd_ctl_elem_value_t *obj, unsigned int idx, long val)
|
||||
{
|
||||
assert(obj);
|
||||
obj->value.integer.value[idx] = val;
|
||||
}
|
||||
|
||||
void snd_ctl_elem_set_enumerated(snd_ctl_elem_t *obj, unsigned int idx, unsigned int val)
|
||||
void snd_ctl_elem_value_set_enumerated(snd_ctl_elem_value_t *obj, unsigned int idx, unsigned int val)
|
||||
{
|
||||
assert(obj);
|
||||
obj->value.enumerated.item[idx] = val;
|
||||
}
|
||||
|
||||
void snd_ctl_elem_set_byte(snd_ctl_elem_t *obj, unsigned int idx, unsigned char val)
|
||||
void snd_ctl_elem_value_set_byte(snd_ctl_elem_value_t *obj, unsigned int idx, unsigned char val)
|
||||
{
|
||||
assert(obj);
|
||||
obj->value.bytes.data[idx] = val;
|
||||
}
|
||||
|
||||
const void * snd_ctl_elem_get_bytes(const snd_ctl_elem_t *obj)
|
||||
const void * snd_ctl_elem_value_get_bytes(const snd_ctl_elem_value_t *obj)
|
||||
{
|
||||
assert(obj);
|
||||
return obj->value.bytes.data;
|
||||
}
|
||||
|
||||
void snd_ctl_elem_get_iec958(const snd_ctl_elem_t *obj, snd_aes_iec958_t *ptr)
|
||||
void snd_ctl_elem_value_get_iec958(const snd_ctl_elem_value_t *obj, snd_aes_iec958_t *ptr)
|
||||
{
|
||||
assert(obj && ptr);
|
||||
*ptr = obj->value.iec958;
|
||||
}
|
||||
|
||||
void snd_ctl_elem_set_iec958(snd_ctl_elem_t *obj, const snd_aes_iec958_t *ptr)
|
||||
void snd_ctl_elem_value_set_iec958(snd_ctl_elem_value_t *obj, const snd_aes_iec958_t *ptr)
|
||||
{
|
||||
assert(obj && ptr);
|
||||
obj->value.iec958 = *ptr;
|
||||
}
|
||||
|
||||
size_t snd_hctl_elem_sizeof()
|
||||
{
|
||||
return sizeof(snd_hctl_elem_t);
|
||||
}
|
||||
|
||||
int snd_hctl_elem_malloc(snd_hctl_elem_t **ptr)
|
||||
{
|
||||
assert(ptr);
|
||||
*ptr = calloc(1, sizeof(snd_hctl_elem_t));
|
||||
if (!*ptr)
|
||||
return -ENOMEM;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void snd_hctl_elem_free(snd_hctl_elem_t *obj)
|
||||
{
|
||||
free(obj);
|
||||
}
|
||||
|
||||
void snd_hctl_elem_copy(snd_hctl_elem_t *dst, const snd_hctl_elem_t *src)
|
||||
{
|
||||
assert(dst && src);
|
||||
*dst = *src;
|
||||
}
|
||||
|
||||
void snd_hctl_elem_get_id(const snd_hctl_elem_t *obj, snd_ctl_elem_id_t *ptr)
|
||||
{
|
||||
assert(obj && ptr);
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ extern int receive_fd(int socket, void *data, size_t len, int *fd);
|
|||
|
||||
static int snd_ctl_shm_action(snd_ctl_t *ctl)
|
||||
{
|
||||
snd_ctl_shm_t *shm = ctl->private;
|
||||
snd_ctl_shm_t *shm = ctl->private_data;
|
||||
int err;
|
||||
char buf[1];
|
||||
volatile snd_ctl_shm_ctrl_t *ctrl = shm->ctrl;
|
||||
|
|
@ -64,7 +64,7 @@ static int snd_ctl_shm_action(snd_ctl_t *ctl)
|
|||
|
||||
static int snd_ctl_shm_action_fd(snd_ctl_t *ctl, int *fd)
|
||||
{
|
||||
snd_ctl_shm_t *shm = ctl->private;
|
||||
snd_ctl_shm_t *shm = ctl->private_data;
|
||||
int err;
|
||||
char buf[1];
|
||||
volatile snd_ctl_shm_ctrl_t *ctrl = shm->ctrl;
|
||||
|
|
@ -83,7 +83,7 @@ static int snd_ctl_shm_action_fd(snd_ctl_t *ctl, int *fd)
|
|||
|
||||
static int snd_ctl_shm_close(snd_ctl_t *ctl)
|
||||
{
|
||||
snd_ctl_shm_t *shm = ctl->private;
|
||||
snd_ctl_shm_t *shm = ctl->private_data;
|
||||
volatile snd_ctl_shm_ctrl_t *ctrl = shm->ctrl;
|
||||
int result;
|
||||
ctrl->cmd = SND_CTL_IOCTL_CLOSE;
|
||||
|
|
@ -101,7 +101,7 @@ static int snd_ctl_shm_nonblock(snd_ctl_t *handle ATTRIBUTE_UNUSED, int nonblock
|
|||
|
||||
static int snd_ctl_shm_async(snd_ctl_t *ctl, int sig, pid_t pid)
|
||||
{
|
||||
snd_ctl_shm_t *shm = ctl->private;
|
||||
snd_ctl_shm_t *shm = ctl->private_data;
|
||||
volatile snd_ctl_shm_ctrl_t *ctrl = shm->ctrl;
|
||||
ctrl->cmd = SND_CTL_IOCTL_ASYNC;
|
||||
ctrl->u.async.sig = sig;
|
||||
|
|
@ -113,7 +113,7 @@ static int snd_ctl_shm_async(snd_ctl_t *ctl, int sig, pid_t pid)
|
|||
|
||||
static int snd_ctl_shm_poll_descriptor(snd_ctl_t *ctl)
|
||||
{
|
||||
snd_ctl_shm_t *shm = ctl->private;
|
||||
snd_ctl_shm_t *shm = ctl->private_data;
|
||||
volatile snd_ctl_shm_ctrl_t *ctrl = shm->ctrl;
|
||||
int fd, err;
|
||||
ctrl->cmd = SND_CTL_IOCTL_POLL_DESCRIPTOR;
|
||||
|
|
@ -125,7 +125,7 @@ static int snd_ctl_shm_poll_descriptor(snd_ctl_t *ctl)
|
|||
|
||||
static int snd_ctl_shm_hw_info(snd_ctl_t *ctl, snd_ctl_card_info_t *info)
|
||||
{
|
||||
snd_ctl_shm_t *shm = ctl->private;
|
||||
snd_ctl_shm_t *shm = ctl->private_data;
|
||||
volatile snd_ctl_shm_ctrl_t *ctrl = shm->ctrl;
|
||||
int err;
|
||||
// ctrl->u.hw_info = *info;
|
||||
|
|
@ -139,7 +139,7 @@ static int snd_ctl_shm_hw_info(snd_ctl_t *ctl, snd_ctl_card_info_t *info)
|
|||
|
||||
static int snd_ctl_shm_elem_list(snd_ctl_t *ctl, snd_ctl_elem_list_t *list)
|
||||
{
|
||||
snd_ctl_shm_t *shm = ctl->private;
|
||||
snd_ctl_shm_t *shm = ctl->private_data;
|
||||
volatile snd_ctl_shm_ctrl_t *ctrl = shm->ctrl;
|
||||
size_t maxsize = CTL_SHM_DATA_MAXLEN;
|
||||
size_t bytes = list->space * sizeof(*list->pids);
|
||||
|
|
@ -161,7 +161,7 @@ static int snd_ctl_shm_elem_list(snd_ctl_t *ctl, snd_ctl_elem_list_t *list)
|
|||
|
||||
static int snd_ctl_shm_elem_info(snd_ctl_t *ctl, snd_ctl_elem_info_t *info)
|
||||
{
|
||||
snd_ctl_shm_t *shm = ctl->private;
|
||||
snd_ctl_shm_t *shm = ctl->private_data;
|
||||
volatile snd_ctl_shm_ctrl_t *ctrl = shm->ctrl;
|
||||
int err;
|
||||
ctrl->u.element_info = *info;
|
||||
|
|
@ -173,9 +173,9 @@ static int snd_ctl_shm_elem_info(snd_ctl_t *ctl, snd_ctl_elem_info_t *info)
|
|||
return err;
|
||||
}
|
||||
|
||||
static int snd_ctl_shm_elem_read(snd_ctl_t *ctl, snd_ctl_elem_t *control)
|
||||
static int snd_ctl_shm_elem_read(snd_ctl_t *ctl, snd_ctl_elem_value_t *control)
|
||||
{
|
||||
snd_ctl_shm_t *shm = ctl->private;
|
||||
snd_ctl_shm_t *shm = ctl->private_data;
|
||||
volatile snd_ctl_shm_ctrl_t *ctrl = shm->ctrl;
|
||||
int err;
|
||||
ctrl->u.element_read = *control;
|
||||
|
|
@ -187,9 +187,9 @@ static int snd_ctl_shm_elem_read(snd_ctl_t *ctl, snd_ctl_elem_t *control)
|
|||
return err;
|
||||
}
|
||||
|
||||
static int snd_ctl_shm_elem_write(snd_ctl_t *ctl, snd_ctl_elem_t *control)
|
||||
static int snd_ctl_shm_elem_write(snd_ctl_t *ctl, snd_ctl_elem_value_t *control)
|
||||
{
|
||||
snd_ctl_shm_t *shm = ctl->private;
|
||||
snd_ctl_shm_t *shm = ctl->private_data;
|
||||
volatile snd_ctl_shm_ctrl_t *ctrl = shm->ctrl;
|
||||
int err;
|
||||
ctrl->u.element_write = *control;
|
||||
|
|
@ -203,7 +203,7 @@ static int snd_ctl_shm_elem_write(snd_ctl_t *ctl, snd_ctl_elem_t *control)
|
|||
|
||||
static int snd_ctl_shm_hwdep_next_device(snd_ctl_t *ctl, int * device)
|
||||
{
|
||||
snd_ctl_shm_t *shm = ctl->private;
|
||||
snd_ctl_shm_t *shm = ctl->private_data;
|
||||
volatile snd_ctl_shm_ctrl_t *ctrl = shm->ctrl;
|
||||
int err;
|
||||
ctrl->u.device = *device;
|
||||
|
|
@ -217,7 +217,7 @@ static int snd_ctl_shm_hwdep_next_device(snd_ctl_t *ctl, int * device)
|
|||
|
||||
static int snd_ctl_shm_hwdep_info(snd_ctl_t *ctl, snd_hwdep_info_t * info)
|
||||
{
|
||||
snd_ctl_shm_t *shm = ctl->private;
|
||||
snd_ctl_shm_t *shm = ctl->private_data;
|
||||
volatile snd_ctl_shm_ctrl_t *ctrl = shm->ctrl;
|
||||
int err;
|
||||
ctrl->u.hwdep_info = *info;
|
||||
|
|
@ -231,7 +231,7 @@ static int snd_ctl_shm_hwdep_info(snd_ctl_t *ctl, snd_hwdep_info_t * info)
|
|||
|
||||
static int snd_ctl_shm_pcm_next_device(snd_ctl_t *ctl, int * device)
|
||||
{
|
||||
snd_ctl_shm_t *shm = ctl->private;
|
||||
snd_ctl_shm_t *shm = ctl->private_data;
|
||||
volatile snd_ctl_shm_ctrl_t *ctrl = shm->ctrl;
|
||||
int err;
|
||||
ctrl->u.device = *device;
|
||||
|
|
@ -245,7 +245,7 @@ static int snd_ctl_shm_pcm_next_device(snd_ctl_t *ctl, int * device)
|
|||
|
||||
static int snd_ctl_shm_pcm_info(snd_ctl_t *ctl, snd_pcm_info_t * info)
|
||||
{
|
||||
snd_ctl_shm_t *shm = ctl->private;
|
||||
snd_ctl_shm_t *shm = ctl->private_data;
|
||||
volatile snd_ctl_shm_ctrl_t *ctrl = shm->ctrl;
|
||||
int err;
|
||||
ctrl->u.pcm_info = *info;
|
||||
|
|
@ -259,7 +259,7 @@ static int snd_ctl_shm_pcm_info(snd_ctl_t *ctl, snd_pcm_info_t * info)
|
|||
|
||||
static int snd_ctl_shm_pcm_prefer_subdevice(snd_ctl_t *ctl, int subdev)
|
||||
{
|
||||
snd_ctl_shm_t *shm = ctl->private;
|
||||
snd_ctl_shm_t *shm = ctl->private_data;
|
||||
volatile snd_ctl_shm_ctrl_t *ctrl = shm->ctrl;
|
||||
int err;
|
||||
ctrl->u.pcm_prefer_subdevice = subdev;
|
||||
|
|
@ -272,7 +272,7 @@ static int snd_ctl_shm_pcm_prefer_subdevice(snd_ctl_t *ctl, int subdev)
|
|||
|
||||
static int snd_ctl_shm_rawmidi_next_device(snd_ctl_t *ctl, int * device)
|
||||
{
|
||||
snd_ctl_shm_t *shm = ctl->private;
|
||||
snd_ctl_shm_t *shm = ctl->private_data;
|
||||
volatile snd_ctl_shm_ctrl_t *ctrl = shm->ctrl;
|
||||
int err;
|
||||
ctrl->u.device = *device;
|
||||
|
|
@ -286,7 +286,7 @@ static int snd_ctl_shm_rawmidi_next_device(snd_ctl_t *ctl, int * device)
|
|||
|
||||
static int snd_ctl_shm_rawmidi_info(snd_ctl_t *ctl, snd_rawmidi_info_t * info)
|
||||
{
|
||||
snd_ctl_shm_t *shm = ctl->private;
|
||||
snd_ctl_shm_t *shm = ctl->private_data;
|
||||
volatile snd_ctl_shm_ctrl_t *ctrl = shm->ctrl;
|
||||
int err;
|
||||
ctrl->u.rawmidi_info = *info;
|
||||
|
|
@ -300,7 +300,7 @@ static int snd_ctl_shm_rawmidi_info(snd_ctl_t *ctl, snd_rawmidi_info_t * info)
|
|||
|
||||
static int snd_ctl_shm_rawmidi_prefer_subdevice(snd_ctl_t *ctl, int subdev)
|
||||
{
|
||||
snd_ctl_shm_t *shm = ctl->private;
|
||||
snd_ctl_shm_t *shm = ctl->private_data;
|
||||
volatile snd_ctl_shm_ctrl_t *ctrl = shm->ctrl;
|
||||
int err;
|
||||
ctrl->u.rawmidi_prefer_subdevice = subdev;
|
||||
|
|
@ -319,7 +319,7 @@ static int snd_ctl_shm_read(snd_ctl_t *ctl, snd_ctl_event_t *event)
|
|||
err = snd_ctl_wait(ctl, -1);
|
||||
if (err < 0)
|
||||
return 0;
|
||||
shm = ctl->private;
|
||||
shm = ctl->private_data;
|
||||
ctrl = shm->ctrl;
|
||||
ctrl->u.read = *event;
|
||||
ctrl->cmd = SND_CTL_IOCTL_READ;
|
||||
|
|
@ -474,7 +474,7 @@ int snd_ctl_shm_open(snd_ctl_t **handlep, const char *name, const char *socket,
|
|||
ctl->name = strdup(name);
|
||||
ctl->type = SND_CTL_TYPE_SHM;
|
||||
ctl->ops = &snd_ctl_shm_ops;
|
||||
ctl->private = shm;
|
||||
ctl->private_data = shm;
|
||||
*handlep = ctl;
|
||||
return 0;
|
||||
|
||||
|
|
@ -491,7 +491,7 @@ extern int is_local(struct hostent *hent);
|
|||
|
||||
int _snd_ctl_shm_open(snd_ctl_t **handlep, char *name, snd_config_t *conf)
|
||||
{
|
||||
snd_config_iterator_t i;
|
||||
snd_config_iterator_t i, next;
|
||||
const char *server = NULL;
|
||||
const char *sname = NULL;
|
||||
snd_config_t *sconfig;
|
||||
|
|
@ -501,7 +501,7 @@ int _snd_ctl_shm_open(snd_ctl_t **handlep, char *name, snd_config_t *conf)
|
|||
int err;
|
||||
int local;
|
||||
struct hostent *h;
|
||||
snd_config_foreach(i, conf) {
|
||||
snd_config_for_each(i, next, conf) {
|
||||
snd_config_t *n = snd_config_iterator_entry(i);
|
||||
const char *id = snd_config_get_id(n);
|
||||
if (strcmp(id, "comment") == 0)
|
||||
|
|
@ -540,7 +540,7 @@ int _snd_ctl_shm_open(snd_ctl_t **handlep, char *name, snd_config_t *conf)
|
|||
ERR("Unknown server %s", server);
|
||||
return -EINVAL;
|
||||
}
|
||||
snd_config_foreach(i, conf) {
|
||||
snd_config_for_each(i, next, conf) {
|
||||
snd_config_t *n = snd_config_iterator_entry(i);
|
||||
const char *id = snd_config_get_id(n);
|
||||
if (strcmp(id, "comment") == 0)
|
||||
|
|
|
|||
|
|
@ -29,12 +29,10 @@
|
|||
#define __USE_GNU
|
||||
#include "control_local.h"
|
||||
|
||||
static int snd_hctl_build(snd_hctl_t *hctl);
|
||||
static int snd_hctl_free(snd_hctl_t *hctl);
|
||||
static int snd_hctl_compare_default(const snd_hctl_elem_t *c1,
|
||||
const snd_hctl_elem_t *c2);
|
||||
|
||||
int snd_hctl_open(snd_hctl_t **hctlp, char *name)
|
||||
int snd_hctl_open(snd_hctl_t **hctlp, const char *name)
|
||||
{
|
||||
snd_hctl_t *hctl;
|
||||
snd_ctl_t *ctl;
|
||||
|
|
@ -48,12 +46,8 @@ int snd_hctl_open(snd_hctl_t **hctlp, char *name)
|
|||
snd_ctl_close(ctl);
|
||||
return -ENOMEM;
|
||||
}
|
||||
INIT_LIST_HEAD(&hctl->hlist);
|
||||
INIT_LIST_HEAD(&hctl->elems);
|
||||
hctl->ctl = ctl;
|
||||
if ((err = snd_hctl_build(hctl)) < 0) {
|
||||
snd_hctl_close(hctl);
|
||||
return err;
|
||||
}
|
||||
*hctlp = hctl;
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -63,28 +57,33 @@ int snd_hctl_close(snd_hctl_t *hctl)
|
|||
int err;
|
||||
|
||||
assert(hctl);
|
||||
assert(hctl->ctl);
|
||||
err = snd_ctl_close(hctl->ctl);
|
||||
snd_hctl_free(hctl);
|
||||
free(hctl);
|
||||
return err;
|
||||
}
|
||||
|
||||
const char *snd_hctl_name(snd_hctl_t *hctl)
|
||||
{
|
||||
assert(hctl);
|
||||
return snd_ctl_name(hctl->ctl);
|
||||
}
|
||||
|
||||
int snd_hctl_nonblock(snd_hctl_t *hctl, int nonblock)
|
||||
{
|
||||
assert(hctl && hctl->ctl);
|
||||
assert(hctl);
|
||||
return snd_ctl_nonblock(hctl->ctl, nonblock);
|
||||
}
|
||||
|
||||
int snd_hctl_async(snd_hctl_t *hctl, int sig, pid_t pid)
|
||||
{
|
||||
assert(hctl && hctl->ctl);
|
||||
assert(hctl);
|
||||
return snd_ctl_async(hctl->ctl, sig, pid);
|
||||
}
|
||||
|
||||
int snd_hctl_poll_descriptor(snd_hctl_t *hctl)
|
||||
{
|
||||
assert(hctl && hctl->ctl);
|
||||
assert(hctl);
|
||||
return snd_ctl_poll_descriptor(hctl->ctl);
|
||||
}
|
||||
|
||||
|
|
@ -94,12 +93,12 @@ static int _snd_hctl_find_elem(snd_hctl_t *hctl, const snd_ctl_elem_id_t *id, in
|
|||
int c = 0;
|
||||
int idx = -1;
|
||||
assert(hctl && id);
|
||||
assert(hctl->hcompare);
|
||||
assert(hctl->compare);
|
||||
l = 0;
|
||||
u = hctl->hcount;
|
||||
u = hctl->count;
|
||||
while (l < u) {
|
||||
idx = (l + u) / 2;
|
||||
c = hctl->hcompare((snd_hctl_elem_t *) id, hctl->helems[idx]);
|
||||
c = hctl->compare((snd_hctl_elem_t *) id, hctl->pelems[idx]);
|
||||
if (c < 0)
|
||||
u = idx;
|
||||
else if (c > 0)
|
||||
|
|
@ -111,65 +110,75 @@ static int _snd_hctl_find_elem(snd_hctl_t *hctl, const snd_ctl_elem_id_t *id, in
|
|||
return idx;
|
||||
}
|
||||
|
||||
int snd_hctl_throw_event(snd_hctl_t *hctl, snd_ctl_event_type_t event,
|
||||
snd_hctl_elem_t *elem)
|
||||
{
|
||||
if (hctl->callback)
|
||||
return hctl->callback(hctl, event, elem);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int snd_hctl_elem_throw_event(snd_hctl_elem_t *elem,
|
||||
snd_ctl_event_type_t event)
|
||||
{
|
||||
if (elem->callback)
|
||||
return elem->callback(elem, event);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int snd_hctl_elem_add(snd_hctl_t *hctl, snd_hctl_elem_t *elem)
|
||||
{
|
||||
int dir;
|
||||
int idx;
|
||||
if (hctl->hcount == hctl->halloc) {
|
||||
if (hctl->count == hctl->alloc) {
|
||||
snd_hctl_elem_t **h;
|
||||
hctl->halloc += 32;
|
||||
h = realloc(hctl->helems, sizeof(*h) * hctl->halloc);
|
||||
hctl->alloc += 32;
|
||||
h = realloc(hctl->pelems, sizeof(*h) * hctl->alloc);
|
||||
if (!h)
|
||||
return -ENOMEM;
|
||||
hctl->helems = h;
|
||||
hctl->pelems = h;
|
||||
}
|
||||
if (hctl->hcount == 0) {
|
||||
list_add_tail(&elem->list, &hctl->hlist);
|
||||
hctl->helems[0] = elem;
|
||||
if (hctl->count == 0) {
|
||||
list_add_tail(&elem->list, &hctl->elems);
|
||||
hctl->pelems[0] = elem;
|
||||
} else {
|
||||
idx = _snd_hctl_find_elem(hctl, &elem->id, &dir);
|
||||
assert(dir != 0);
|
||||
if (dir > 0) {
|
||||
list_add(&elem->list, &hctl->helems[idx]->list);
|
||||
list_add(&elem->list, &hctl->pelems[idx]->list);
|
||||
} else {
|
||||
list_add_tail(&elem->list, &hctl->helems[idx]->list);
|
||||
list_add_tail(&elem->list, &hctl->pelems[idx]->list);
|
||||
idx++;
|
||||
}
|
||||
memmove(hctl->helems + idx + 1,
|
||||
hctl->helems + idx,
|
||||
hctl->hcount - idx);
|
||||
memmove(hctl->pelems + idx + 1,
|
||||
hctl->pelems + idx,
|
||||
hctl->count - idx);
|
||||
}
|
||||
hctl->hcount++;
|
||||
if (hctl->callback) {
|
||||
int res = hctl->callback(hctl, SND_CTL_EVENT_ADD, elem);
|
||||
if (res < 0)
|
||||
return res;
|
||||
}
|
||||
return 0;
|
||||
hctl->count++;
|
||||
return snd_hctl_throw_event(hctl, SND_CTL_EVENT_ADD, elem);
|
||||
}
|
||||
|
||||
static void snd_hctl_elem_remove(snd_hctl_t *hctl, unsigned int idx)
|
||||
{
|
||||
snd_hctl_elem_t *elem = hctl->helems[idx];
|
||||
snd_hctl_elem_t *elem = hctl->pelems[idx];
|
||||
unsigned int m;
|
||||
if (elem->callback)
|
||||
elem->callback(elem, SND_CTL_EVENT_REMOVE);
|
||||
snd_hctl_elem_throw_event(elem, SND_CTL_EVENT_REMOVE);
|
||||
list_del(&elem->list);
|
||||
free(elem);
|
||||
hctl->hcount--;
|
||||
m = hctl->hcount - idx;
|
||||
hctl->count--;
|
||||
m = hctl->count - idx;
|
||||
if (m > 0)
|
||||
memmove(hctl->helems + idx, hctl->helems + idx + 1, m);
|
||||
memmove(hctl->pelems + idx, hctl->pelems + idx + 1, m);
|
||||
}
|
||||
|
||||
static int snd_hctl_free(snd_hctl_t *hctl)
|
||||
int snd_hctl_free(snd_hctl_t *hctl)
|
||||
{
|
||||
while (hctl->hcount > 0)
|
||||
snd_hctl_elem_remove(hctl, hctl->hcount - 1);
|
||||
free(hctl->helems);
|
||||
hctl->helems = 0;
|
||||
hctl->halloc = 0;
|
||||
INIT_LIST_HEAD(&hctl->hlist);
|
||||
while (hctl->count > 0)
|
||||
snd_hctl_elem_remove(hctl, hctl->count - 1);
|
||||
free(hctl->pelems);
|
||||
hctl->pelems = 0;
|
||||
hctl->alloc = 0;
|
||||
INIT_LIST_HEAD(&hctl->elems);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -177,21 +186,21 @@ static void snd_hctl_sort(snd_hctl_t *hctl)
|
|||
{
|
||||
unsigned int k;
|
||||
int compar(const void *a, const void *b) {
|
||||
return hctl->hcompare(*(const snd_hctl_elem_t **) a,
|
||||
return hctl->compare(*(const snd_hctl_elem_t **) a,
|
||||
*(const snd_hctl_elem_t **) b);
|
||||
}
|
||||
assert(hctl);
|
||||
assert(hctl->hcompare);
|
||||
INIT_LIST_HEAD(&hctl->hlist);
|
||||
qsort(hctl->helems, hctl->hcount, sizeof(*hctl->helems), compar);
|
||||
for (k = 0; k < hctl->hcount; k++)
|
||||
list_add_tail(&hctl->helems[k]->list, &hctl->hlist);
|
||||
assert(hctl->compare);
|
||||
INIT_LIST_HEAD(&hctl->elems);
|
||||
qsort(hctl->pelems, hctl->count, sizeof(*hctl->pelems), compar);
|
||||
for (k = 0; k < hctl->count; k++)
|
||||
list_add_tail(&hctl->pelems[k]->list, &hctl->elems);
|
||||
}
|
||||
|
||||
void snd_hctl_set_compare(snd_hctl_t *hctl, snd_hctl_compare_t hsort)
|
||||
{
|
||||
assert(hctl);
|
||||
hctl->hcompare = hsort == NULL ? snd_hctl_compare_default : hsort;
|
||||
hctl->compare = hsort == NULL ? snd_hctl_compare_default : hsort;
|
||||
snd_hctl_sort(hctl);
|
||||
}
|
||||
|
||||
|
|
@ -307,23 +316,23 @@ static int snd_hctl_compare_default(const snd_hctl_elem_t *c1,
|
|||
snd_hctl_elem_t *snd_hctl_first_elem(snd_hctl_t *hctl)
|
||||
{
|
||||
assert(hctl);
|
||||
if (list_empty(&hctl->hlist))
|
||||
if (list_empty(&hctl->elems))
|
||||
return NULL;
|
||||
return list_entry(hctl->hlist.next, snd_hctl_elem_t, list);
|
||||
return list_entry(hctl->elems.next, snd_hctl_elem_t, list);
|
||||
}
|
||||
|
||||
snd_hctl_elem_t *snd_hctl_last_elem(snd_hctl_t *hctl)
|
||||
{
|
||||
assert(hctl);
|
||||
if (list_empty(&hctl->hlist))
|
||||
if (list_empty(&hctl->elems))
|
||||
return NULL;
|
||||
return list_entry(hctl->hlist.prev, snd_hctl_elem_t, list);
|
||||
return list_entry(hctl->elems.prev, snd_hctl_elem_t, list);
|
||||
}
|
||||
|
||||
snd_hctl_elem_t *snd_hctl_elem_next(snd_hctl_elem_t *elem)
|
||||
{
|
||||
assert(elem);
|
||||
if (elem->list.next == &elem->hctl->hlist)
|
||||
if (elem->list.next == &elem->hctl->elems)
|
||||
return NULL;
|
||||
return list_entry(elem->list.next, snd_hctl_elem_t, list);
|
||||
}
|
||||
|
|
@ -331,7 +340,7 @@ snd_hctl_elem_t *snd_hctl_elem_next(snd_hctl_elem_t *elem)
|
|||
snd_hctl_elem_t *snd_hctl_elem_prev(snd_hctl_elem_t *elem)
|
||||
{
|
||||
assert(elem);
|
||||
if (elem->list.prev == &elem->hctl->hlist)
|
||||
if (elem->list.prev == &elem->hctl->elems)
|
||||
return NULL;
|
||||
return list_entry(elem->list.prev, snd_hctl_elem_t, list);
|
||||
}
|
||||
|
|
@ -342,10 +351,10 @@ snd_hctl_elem_t *snd_hctl_find_elem(snd_hctl_t *hctl, const snd_ctl_elem_id_t *i
|
|||
int res = _snd_hctl_find_elem(hctl, id, &dir);
|
||||
if (res < 0 || dir != 0)
|
||||
return NULL;
|
||||
return hctl->helems[res];
|
||||
return hctl->pelems[res];
|
||||
}
|
||||
|
||||
static int snd_hctl_build(snd_hctl_t *hctl)
|
||||
int snd_hctl_load(snd_hctl_t *hctl)
|
||||
{
|
||||
snd_ctl_elem_list_t list;
|
||||
int err = 0;
|
||||
|
|
@ -353,8 +362,8 @@ static int snd_hctl_build(snd_hctl_t *hctl)
|
|||
|
||||
assert(hctl);
|
||||
assert(hctl->ctl);
|
||||
assert(hctl->hcount == 0);
|
||||
assert(list_empty(&hctl->hlist));
|
||||
assert(hctl->count == 0);
|
||||
assert(list_empty(&hctl->elems));
|
||||
memset(&list, 0, sizeof(list));
|
||||
if ((err = snd_ctl_elem_list(hctl->ctl, &list)) < 0)
|
||||
goto _end;
|
||||
|
|
@ -365,11 +374,11 @@ static int snd_hctl_build(snd_hctl_t *hctl)
|
|||
if ((err = snd_ctl_elem_list(hctl->ctl, &list)) < 0)
|
||||
goto _end;
|
||||
}
|
||||
if (hctl->halloc < list.count) {
|
||||
hctl->halloc = list.count;
|
||||
free(hctl->helems);
|
||||
hctl->helems = malloc(hctl->halloc * sizeof(*hctl->helems));
|
||||
if (!hctl->helems) {
|
||||
if (hctl->alloc < list.count) {
|
||||
hctl->alloc = list.count;
|
||||
free(hctl->pelems);
|
||||
hctl->pelems = malloc(hctl->alloc * sizeof(*hctl->pelems));
|
||||
if (!hctl->pelems) {
|
||||
err = -ENOMEM;
|
||||
goto _end;
|
||||
}
|
||||
|
|
@ -384,20 +393,18 @@ static int snd_hctl_build(snd_hctl_t *hctl)
|
|||
}
|
||||
elem->id = list.pids[idx];
|
||||
elem->hctl = hctl;
|
||||
hctl->helems[idx] = elem;
|
||||
list_add_tail(&elem->list, &hctl->hlist);
|
||||
hctl->hcount++;
|
||||
hctl->pelems[idx] = elem;
|
||||
list_add_tail(&elem->list, &hctl->elems);
|
||||
hctl->count++;
|
||||
}
|
||||
if (!hctl->hcompare)
|
||||
hctl->hcompare = snd_hctl_compare_default;
|
||||
if (!hctl->compare)
|
||||
hctl->compare = snd_hctl_compare_default;
|
||||
snd_hctl_sort(hctl);
|
||||
if (hctl->callback) {
|
||||
for (idx = 0; idx < hctl->hcount; idx++) {
|
||||
int res = hctl->callback(hctl, SND_CTL_EVENT_ADD,
|
||||
hctl->helems[idx]);
|
||||
if (res < 0)
|
||||
return res;
|
||||
}
|
||||
for (idx = 0; idx < hctl->count; idx++) {
|
||||
int res = snd_hctl_throw_event(hctl, SND_CTL_EVENT_ADD,
|
||||
hctl->pelems[idx]);
|
||||
if (res < 0)
|
||||
return res;
|
||||
}
|
||||
_end:
|
||||
if (list.pids)
|
||||
|
|
@ -425,10 +432,10 @@ void *snd_hctl_get_callback_private(snd_hctl_t *hctl)
|
|||
|
||||
unsigned int snd_hctl_get_count(snd_hctl_t *hctl)
|
||||
{
|
||||
return hctl->hcount;
|
||||
return hctl->count;
|
||||
}
|
||||
|
||||
int snd_hctl_event(snd_hctl_t *hctl, snd_ctl_event_t *event)
|
||||
int snd_hctl_handle_event(snd_hctl_t *hctl, snd_ctl_event_t *event)
|
||||
{
|
||||
snd_hctl_elem_t *elem;
|
||||
int res;
|
||||
|
|
@ -447,17 +454,12 @@ int snd_hctl_event(snd_hctl_t *hctl, snd_ctl_event_t *event)
|
|||
break;
|
||||
}
|
||||
case SND_CTL_EVENT_VALUE:
|
||||
case SND_CTL_EVENT_CHANGE:
|
||||
case SND_CTL_EVENT_INFO:
|
||||
elem = snd_hctl_find_elem(hctl, &event->data.id);
|
||||
assert(elem);
|
||||
if (!elem)
|
||||
return -ENOENT;
|
||||
if (elem->callback) {
|
||||
res = elem->callback(elem, event->type);
|
||||
if (res < 0)
|
||||
return res;
|
||||
}
|
||||
break;
|
||||
return snd_hctl_elem_throw_event(elem, event->type);
|
||||
case SND_CTL_EVENT_ADD:
|
||||
elem = calloc(1, sizeof(snd_hctl_elem_t));
|
||||
if (elem == NULL)
|
||||
|
|
@ -470,12 +472,13 @@ int snd_hctl_event(snd_hctl_t *hctl, snd_ctl_event_t *event)
|
|||
break;
|
||||
case SND_CTL_EVENT_REBUILD:
|
||||
snd_hctl_free(hctl);
|
||||
res = snd_hctl_build(hctl);
|
||||
if (hctl->callback) {
|
||||
res = hctl->callback(hctl, event->type, NULL);
|
||||
if (res < 0)
|
||||
return res;
|
||||
}
|
||||
res = snd_hctl_load(hctl);
|
||||
if (res < 0)
|
||||
return res;
|
||||
#if 0
|
||||
/* I don't think this have to be passed to higher level */
|
||||
return hctl_event(hctl, event->type, NULL);
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
|
|
@ -484,7 +487,7 @@ int snd_hctl_event(snd_hctl_t *hctl, snd_ctl_event_t *event)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int snd_hctl_events(snd_hctl_t *hctl)
|
||||
int snd_hctl_handle_events(snd_hctl_t *hctl)
|
||||
{
|
||||
snd_ctl_event_t event;
|
||||
int res;
|
||||
|
|
@ -494,7 +497,7 @@ int snd_hctl_events(snd_hctl_t *hctl)
|
|||
while ((res = snd_ctl_read(hctl->ctl, &event)) != 0) {
|
||||
if (res < 0)
|
||||
return res;
|
||||
res = snd_hctl_event(hctl, &event);
|
||||
res = snd_hctl_handle_event(hctl, &event);
|
||||
if (res < 0)
|
||||
return res;
|
||||
}
|
||||
|
|
@ -510,7 +513,7 @@ int snd_hctl_elem_info(snd_hctl_elem_t *elem, snd_ctl_elem_info_t *info)
|
|||
return snd_ctl_elem_info(elem->hctl->ctl, info);
|
||||
}
|
||||
|
||||
int snd_hctl_elem_read(snd_hctl_elem_t *elem, snd_ctl_elem_t * value)
|
||||
int snd_hctl_elem_read(snd_hctl_elem_t *elem, snd_ctl_elem_value_t * value)
|
||||
{
|
||||
assert(elem);
|
||||
assert(elem->hctl);
|
||||
|
|
@ -519,7 +522,7 @@ int snd_hctl_elem_read(snd_hctl_elem_t *elem, snd_ctl_elem_t * value)
|
|||
return snd_ctl_elem_read(elem->hctl->ctl, value);
|
||||
}
|
||||
|
||||
int snd_hctl_elem_write(snd_hctl_elem_t *elem, snd_ctl_elem_t * value)
|
||||
int snd_hctl_elem_write(snd_hctl_elem_t *elem, snd_ctl_elem_value_t * value)
|
||||
{
|
||||
assert(elem);
|
||||
assert(elem->hctl);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue