Control API encapsulation. Better names for kernel API. Simpler PCM hw_params API. Added missing const.

This commit is contained in:
Abramo Bagnara 2001-02-06 23:48:10 +00:00
parent ccb399f0cd
commit 8f0cb26fdf
71 changed files with 2001 additions and 694 deletions

View file

@ -1,7 +1,7 @@
EXTRA_LTLIBRARIES = libcontrol.la
libcontrol_la_SOURCES = cards.c controls.c bag.c defaults.c \
control.c control_hw.c control_shm.c
control.c control_m4.c control_hw.c control_shm.c
all: libcontrol.la

View file

@ -23,10 +23,8 @@
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <assert.h>
#define __USE_GNU
#include <search.h>
#include "control_local.h"

View file

@ -23,7 +23,6 @@
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include <fcntl.h>
#include <sys/ioctl.h>
@ -73,7 +72,7 @@ int snd_card_get_index(const char *string)
{
int card;
snd_ctl_t *handle;
snd_ctl_hw_info_t info;
snd_ctl_info_t info;
if (!string || *string == '\0')
return -EINVAL;
@ -91,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_hw_info(handle, &info) < 0) {
if (snd_ctl_info(handle, &info) < 0) {
snd_ctl_close(handle);
continue;
}
@ -105,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_hw_info_t info;
snd_ctl_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_hw_info(handle, &info)) < 0) {
if ((err = snd_ctl_info(handle, &info)) < 0) {
snd_ctl_close(handle);
return err;
}
@ -126,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_hw_info_t info;
snd_ctl_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_hw_info(handle, &info)) < 0) {
if ((err = snd_ctl_info(handle, &info)) < 0) {
snd_ctl_close(handle);
return err;
}

View file

@ -24,9 +24,7 @@
#include <stdarg.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <assert.h>
#include <dlfcn.h>
#include "control_local.h"
@ -50,7 +48,7 @@ int snd_ctl_poll_descriptor(snd_ctl_t *ctl)
return ctl->ops->poll_descriptor(ctl);
}
int snd_ctl_hw_info(snd_ctl_t *ctl, snd_ctl_hw_info_t *info)
int snd_ctl_info(snd_ctl_t *ctl, snd_ctl_info_t *info)
{
assert(ctl && info);
return ctl->ops->hw_info(ctl, info);
@ -175,11 +173,11 @@ int snd_ctl_read(snd_ctl_t *ctl, snd_ctl_callbacks_t * callbacks)
int snd_ctl_open(snd_ctl_t **ctlp, char *name)
{
char *str;
const char *str;
int err;
snd_config_t *ctl_conf, *conf, *type_conf;
snd_config_iterator_t i;
char *lib = NULL, *open = NULL;
const char *lib = NULL, *open = NULL;
int (*open_func)(snd_ctl_t **ctlp, char *name, snd_config_t *conf);
void *h;
assert(ctlp && name);
@ -240,3 +238,75 @@ 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)
{
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 EVENT(v) [SND_CTL_EVENT_##v] = #v
const char *snd_control_type_names[] = {
TYPE(NONE),
TYPE(BOOLEAN),
TYPE(INTEGER),
TYPE(ENUMERATED),
TYPE(BYTES),
TYPE(IEC958),
};
const char *snd_control_iface_names[] = {
IFACE(CARD),
IFACE(HWDEP),
IFACE(MIXER),
IFACE(PCM),
IFACE(RAWMIDI),
IFACE(TIMER),
IFACE(SEQUENCER),
};
const char *snd_ctl_event_type_names[] = {
EVENT(REBUILD),
EVENT(VALUE),
EVENT(CHANGE),
EVENT(ADD),
EVENT(REMOVE),
};
const char *snd_control_type_name(snd_control_type_t type)
{
assert(type <= SND_CONTROL_TYPE_LAST);
return snd_control_type_names[snd_enum_to_int(type)];
}
const char *snd_control_iface_name(snd_control_iface_t iface)
{
assert(iface <= SND_CONTROL_IFACE_LAST);
return snd_control_iface_names[snd_enum_to_int(iface)];
}
const char *snd_ctl_event_type_name(snd_ctl_event_type_t type)
{
assert(type <= SND_CTL_EVENT_LAST);
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)
{
obj->pids = calloc(entries, sizeof(*obj->pids));
if (!obj->pids) {
obj->space = 0;
return -ENOMEM;
}
obj->space = entries;
return 0;
}
void snd_control_list_free_space(snd_control_list_t *obj)
{
free(obj->pids);
obj->pids = NULL;
}

View file

@ -24,10 +24,8 @@
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <assert.h>
#include "control_local.h"
#define SNDRV_FILE_CONTROL "/dev/snd/controlC%i"
@ -53,10 +51,10 @@ 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_hw_info_t *info)
static int snd_ctl_hw_hw_info(snd_ctl_t *handle, snd_ctl_info_t *info)
{
snd_ctl_hw_t *hw = handle->private;
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_HW_INFO, info) < 0)
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_INFO, info) < 0)
return -errno;
return 0;
}
@ -182,7 +180,7 @@ snd_ctl_ops_t snd_ctl_hw_ops = {
read: snd_ctl_hw_read,
};
int snd_ctl_hw_open(snd_ctl_t **handle, char *name, int card)
int snd_ctl_hw_open(snd_ctl_t **handle, const char *name, int card)
{
int fd, ver;
char filename[32];
@ -234,7 +232,7 @@ int _snd_ctl_hw_open(snd_ctl_t **handlep, char *name, snd_config_t *conf)
{
snd_config_iterator_t i;
long card = -1;
char *str;
const char *str;
int err;
snd_config_foreach(i, conf) {
snd_config_t *n = snd_config_entry(i);

View file

@ -19,14 +19,13 @@
*
*/
#include <assert.h>
#include "local.h"
#include "list.h"
typedef struct {
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_hw_info_t *info);
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);
@ -53,12 +52,46 @@ struct _snd_ctl {
struct list_head hlist; /* list of all controls */
void *hroot; /* root of controls */
void *hroot_new; /* new croot */
snd_ctl_hsort_t *hsort;
snd_ctl_hcallback_rebuild_t *callback_rebuild;
snd_ctl_hsort_t hsort;
snd_ctl_hcallback_rebuild_t callback_rebuild;
void *callback_rebuild_private_data;
snd_ctl_hcallback_add_t *callback_add;
snd_ctl_hcallback_add_t callback_add;
void *callback_add_private_data;
};
int snd_ctl_hw_open(snd_ctl_t **handle, char *name, int card);
int snd_ctl_shm_open(snd_ctl_t **handlep, char *name, char *socket, char *sname);
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 *reserved[58]; /* reserved for the future use - must be NULL!!! */
};
struct _snd_hcontrol_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 */
};
struct _snd_hcontrol {
snd_control_id_t id; /* must be always on top */
struct list_head list; /* links for list of all hcontrols */
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;
/* private data */
void *private_data;
snd_hcontrol_private_free_t private_free;
/* links */
snd_ctl_t *handle; /* associated handle */
};
int snd_ctl_hw_open(snd_ctl_t **handle, const char *name, int card);
int snd_ctl_shm_open(snd_ctl_t **handlep, const char *name, const char *socket, const char *sname);

937
src/control/control_m4.c Normal file
View file

@ -0,0 +1,937 @@
/*
* Control - Automatically generated functions
* Copyright (c) 2001 by Abramo Bagnara <abramo@alsa-project.org>
*
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#include "control_local.h"
size_t snd_control_id_sizeof()
{
return sizeof(snd_control_id_t);
}
int snd_control_id_malloc(snd_control_id_t **ptr)
{
assert(ptr);
*ptr = calloc(1, sizeof(snd_control_id_t));
if (!*ptr)
return -ENOMEM;
return 0;
}
void snd_control_id_free(snd_control_id_t *obj)
{
free(obj);
}
void snd_control_id_copy(snd_control_id_t *dst, const snd_control_id_t *src)
{
assert(dst && src);
*dst = *src;
}
unsigned int snd_control_id_get_numid(const snd_control_id_t *obj)
{
assert(obj);
return obj->numid;
}
snd_control_iface_t snd_control_id_get_interface(const snd_control_id_t *obj)
{
assert(obj);
return snd_int_to_enum(obj->iface);
}
unsigned int snd_control_id_get_device(const snd_control_id_t *obj)
{
assert(obj);
return obj->device;
}
unsigned int snd_control_id_get_subdevice(const snd_control_id_t *obj)
{
assert(obj);
return obj->subdevice;
}
const char *snd_control_id_get_name(const snd_control_id_t *obj)
{
assert(obj);
return obj->name;
}
unsigned int snd_control_id_get_index(const snd_control_id_t *obj)
{
assert(obj);
return obj->index;
}
void snd_control_id_set_numid(snd_control_id_t *obj, unsigned int val)
{
assert(obj);
obj->numid = val;
}
void snd_control_id_set_interface(snd_control_id_t *obj, snd_control_iface_t val)
{
assert(obj);
obj->iface = snd_enum_to_int(val);
}
void snd_control_id_set_device(snd_control_id_t *obj, unsigned int val)
{
assert(obj);
obj->device = val;
}
void snd_control_id_set_subdevice(snd_control_id_t *obj, unsigned int val)
{
assert(obj);
obj->subdevice = val;
}
void snd_control_id_set_name(snd_control_id_t *obj, const char *val)
{
assert(obj);
strncpy(obj->name, val, sizeof(obj->name));
}
void snd_control_id_set_index(snd_control_id_t *obj, unsigned int val)
{
assert(obj);
obj->index = val;
}
size_t snd_ctl_info_sizeof()
{
return sizeof(snd_ctl_info_t);
}
int snd_ctl_info_malloc(snd_ctl_info_t **ptr)
{
assert(ptr);
*ptr = calloc(1, sizeof(snd_ctl_info_t));
if (!*ptr)
return -ENOMEM;
return 0;
}
void snd_ctl_info_free(snd_ctl_info_t *obj)
{
free(obj);
}
void snd_ctl_info_copy(snd_ctl_info_t *dst, const snd_ctl_info_t *src)
{
assert(dst && src);
*dst = *src;
}
int snd_ctl_info_get_card(const snd_ctl_info_t *obj)
{
assert(obj);
return obj->card;
}
snd_card_type_t snd_ctl_info_get_type(const snd_ctl_info_t *obj)
{
assert(obj);
return snd_int_to_enum(obj->type);
}
const char *snd_ctl_info_get_id(const snd_ctl_info_t *obj)
{
assert(obj);
return obj->id;
}
const char *snd_ctl_info_get_abbreviation(const snd_ctl_info_t *obj)
{
assert(obj);
return obj->abbreviation;
}
const char *snd_ctl_info_get_name(const snd_ctl_info_t *obj)
{
assert(obj);
return obj->name;
}
const char *snd_ctl_info_get_longname(const snd_ctl_info_t *obj)
{
assert(obj);
return obj->longname;
}
const char *snd_ctl_info_get_mixerid(const snd_ctl_info_t *obj)
{
assert(obj);
return obj->mixerid;
}
const char *snd_ctl_info_get_mixername(const snd_ctl_info_t *obj)
{
assert(obj);
return obj->mixername;
}
size_t snd_ctl_event_sizeof()
{
return sizeof(snd_ctl_event_t);
}
int snd_ctl_event_malloc(snd_ctl_event_t **ptr)
{
assert(ptr);
*ptr = calloc(1, sizeof(snd_ctl_event_t));
if (!*ptr)
return -ENOMEM;
return 0;
}
void snd_ctl_event_free(snd_ctl_event_t *obj)
{
free(obj);
}
void snd_ctl_event_copy(snd_ctl_event_t *dst, const snd_ctl_event_t *src)
{
assert(dst && src);
*dst = *src;
}
snd_ctl_event_type_t snd_ctl_event_get_type(const snd_ctl_event_t *obj)
{
assert(obj);
return snd_int_to_enum(obj->type);
}
unsigned int snd_ctl_event_get_numid(const snd_ctl_event_t *obj)
{
assert(obj);
assert(obj->type != SNDRV_CTL_EVENT_REBUILD);
return obj->data.id.numid;
}
void snd_ctl_event_get_id(const snd_ctl_event_t *obj, snd_control_id_t *ptr)
{
assert(obj && ptr);
assert(obj->type != SNDRV_CTL_EVENT_REBUILD);
*ptr = obj->data.id;
}
snd_control_iface_t snd_ctl_event_get_interface(const snd_ctl_event_t *obj)
{
assert(obj);
assert(obj->type != SNDRV_CTL_EVENT_REBUILD);
return snd_int_to_enum(obj->data.id.iface);
}
unsigned int snd_ctl_event_get_device(const snd_ctl_event_t *obj)
{
assert(obj);
assert(obj->type != SNDRV_CTL_EVENT_REBUILD);
return obj->data.id.device;
}
unsigned int snd_ctl_event_get_subdevice(const snd_ctl_event_t *obj)
{
assert(obj);
assert(obj->type != SNDRV_CTL_EVENT_REBUILD);
return obj->data.id.subdevice;
}
const char *snd_ctl_event_get_name(const snd_ctl_event_t *obj)
{
assert(obj);
assert(obj->type != SNDRV_CTL_EVENT_REBUILD);
return obj->data.id.name;
}
unsigned int snd_ctl_event_get_index(const snd_ctl_event_t *obj)
{
assert(obj);
assert(obj->type != SNDRV_CTL_EVENT_REBUILD);
return obj->data.id.index;
}
size_t snd_control_list_sizeof()
{
return sizeof(snd_control_list_t);
}
int snd_control_list_malloc(snd_control_list_t **ptr)
{
assert(ptr);
*ptr = calloc(1, sizeof(snd_control_list_t));
if (!*ptr)
return -ENOMEM;
return 0;
}
void snd_control_list_free(snd_control_list_t *obj)
{
free(obj);
}
void snd_control_list_copy(snd_control_list_t *dst, const snd_control_list_t *src)
{
assert(dst && src);
*dst = *src;
}
void snd_control_list_set_offset(snd_control_list_t *obj, unsigned int val)
{
assert(obj);
obj->offset = val;
}
unsigned int snd_control_list_get_used(const snd_control_list_t *obj)
{
assert(obj);
return obj->used;
}
unsigned int snd_control_list_get_count(const snd_control_list_t *obj)
{
assert(obj);
return obj->count;
}
void snd_control_list_get_id(const snd_control_list_t *obj, unsigned int idx, snd_control_id_t *ptr)
{
assert(obj && ptr);
assert(idx < obj->used);
*ptr = obj->pids[idx];
}
unsigned int snd_control_list_get_numid(const snd_control_list_t *obj, unsigned int idx)
{
assert(obj);
assert(idx < obj->used);
return obj->pids[idx].numid;
}
snd_control_iface_t snd_control_list_get_interface(const snd_control_list_t *obj, unsigned int idx)
{
assert(obj);
assert(idx < obj->used);
return snd_int_to_enum(obj->pids[idx].iface);
}
unsigned int snd_control_list_get_device(const snd_control_list_t *obj, unsigned int idx)
{
assert(obj);
assert(idx < obj->used);
return obj->pids[idx].device;
}
unsigned int snd_control_list_get_subdevice(const snd_control_list_t *obj, unsigned int idx)
{
assert(obj);
assert(idx < obj->used);
return obj->pids[idx].subdevice;
}
const char *snd_control_list_get_name(const snd_control_list_t *obj, unsigned int idx)
{
assert(obj);
assert(idx < obj->used);
return obj->pids[idx].name;
}
unsigned int snd_control_list_get_index(const snd_control_list_t *obj, unsigned int idx)
{
assert(obj);
assert(idx < obj->used);
return obj->pids[idx].index;
}
size_t snd_control_info_sizeof()
{
return sizeof(snd_control_info_t);
}
int snd_control_info_malloc(snd_control_info_t **ptr)
{
assert(ptr);
*ptr = calloc(1, sizeof(snd_control_info_t));
if (!*ptr)
return -ENOMEM;
return 0;
}
void snd_control_info_free(snd_control_info_t *obj)
{
free(obj);
}
void snd_control_info_copy(snd_control_info_t *dst, const snd_control_info_t *src)
{
assert(dst && src);
*dst = *src;
}
snd_control_type_t snd_control_info_get_type(const snd_control_info_t *obj)
{
assert(obj);
return snd_int_to_enum(obj->type);
}
int snd_control_info_is_readable(const snd_control_info_t *obj)
{
assert(obj);
return !!(obj->access & SNDRV_CONTROL_ACCESS_READ);
}
int snd_control_info_is_writable(const snd_control_info_t *obj)
{
assert(obj);
return !!(obj->access & SNDRV_CONTROL_ACCESS_WRITE);
}
int snd_control_info_is_volatile(const snd_control_info_t *obj)
{
assert(obj);
return !!(obj->access & SNDRV_CONTROL_ACCESS_VOLATILE);
}
int snd_control_info_is_inactive(const snd_control_info_t *obj)
{
assert(obj);
return !!(obj->access & SNDRV_CONTROL_ACCESS_INACTIVE);
}
int snd_control_info_is_locked(const snd_control_info_t *obj)
{
assert(obj);
return !!(obj->access & SNDRV_CONTROL_ACCESS_LOCK);
}
int snd_control_info_is_indirect(const snd_control_info_t *obj)
{
assert(obj);
return !!(obj->access & SNDRV_CONTROL_ACCESS_INDIRECT);
}
unsigned int snd_control_info_get_count(const snd_control_info_t *obj)
{
assert(obj);
return obj->count;
}
long snd_control_info_get_min(const snd_control_info_t *obj)
{
assert(obj);
assert(obj->type == SNDRV_CONTROL_TYPE_INTEGER);
return obj->value.integer.min;
}
long snd_control_info_get_max(const snd_control_info_t *obj)
{
assert(obj);
assert(obj->type == SNDRV_CONTROL_TYPE_INTEGER);
return obj->value.integer.max;
}
long snd_control_info_get_step(const snd_control_info_t *obj)
{
assert(obj);
assert(obj->type == SNDRV_CONTROL_TYPE_INTEGER);
return obj->value.integer.step;
}
unsigned int snd_control_info_get_items(const snd_control_info_t *obj)
{
assert(obj);
assert(obj->type == SNDRV_CONTROL_TYPE_ENUMERATED);
return obj->value.enumerated.items;
}
void snd_control_info_set_item(snd_control_info_t *obj, unsigned int val)
{
assert(obj);
obj->value.enumerated.item = val;
}
const char *snd_control_info_get_item_name(const snd_control_info_t *obj)
{
assert(obj);
assert(obj->type == SNDRV_CONTROL_TYPE_ENUMERATED);
return obj->value.enumerated.name;
}
void snd_control_info_get_id(const snd_control_info_t *obj, snd_control_id_t *ptr)
{
assert(obj && ptr);
*ptr = obj->id;
}
unsigned int snd_control_info_get_numid(const snd_control_info_t *obj)
{
assert(obj);
return obj->id.numid;
}
snd_control_iface_t snd_control_info_get_interface(const snd_control_info_t *obj)
{
assert(obj);
return snd_int_to_enum(obj->id.iface);
}
unsigned int snd_control_info_get_device(const snd_control_info_t *obj)
{
assert(obj);
return obj->id.device;
}
unsigned int snd_control_info_get_subdevice(const snd_control_info_t *obj)
{
assert(obj);
return obj->id.subdevice;
}
const char *snd_control_info_get_name(const snd_control_info_t *obj)
{
assert(obj);
return obj->id.name;
}
unsigned int snd_control_info_get_index(const snd_control_info_t *obj)
{
assert(obj);
return obj->id.index;
}
void snd_control_info_set_id(snd_control_info_t *obj, const snd_control_id_t *ptr)
{
assert(obj && ptr);
obj->id = *ptr;
}
void snd_control_info_set_numid(snd_control_info_t *obj, unsigned int val)
{
assert(obj);
obj->id.numid = val;
}
void snd_control_info_set_interface(snd_control_info_t *obj, snd_control_iface_t val)
{
assert(obj);
obj->id.iface = snd_enum_to_int(val);
}
void snd_control_info_set_device(snd_control_info_t *obj, unsigned int val)
{
assert(obj);
obj->id.device = val;
}
void snd_control_info_set_subdevice(snd_control_info_t *obj, unsigned int val)
{
assert(obj);
obj->id.subdevice = val;
}
void snd_control_info_set_name(snd_control_info_t *obj, const char *val)
{
assert(obj);
strncpy(obj->id.name, val, sizeof(obj->id.name));
}
void snd_control_info_set_index(snd_control_info_t *obj, unsigned int val)
{
assert(obj);
obj->id.index = val;
}
size_t snd_control_sizeof()
{
return sizeof(snd_control_t);
}
int snd_control_malloc(snd_control_t **ptr)
{
assert(ptr);
*ptr = calloc(1, sizeof(snd_control_t));
if (!*ptr)
return -ENOMEM;
return 0;
}
void snd_control_free(snd_control_t *obj)
{
free(obj);
}
void snd_control_copy(snd_control_t *dst, const snd_control_t *src)
{
assert(dst && src);
*dst = *src;
}
void snd_control_get_id(const snd_control_t *obj, snd_control_id_t *ptr)
{
assert(obj && ptr);
*ptr = obj->id;
}
unsigned int snd_control_get_numid(const snd_control_t *obj)
{
assert(obj);
return obj->id.numid;
}
snd_control_iface_t snd_control_get_interface(const snd_control_t *obj)
{
assert(obj);
return snd_int_to_enum(obj->id.iface);
}
unsigned int snd_control_get_device(const snd_control_t *obj)
{
assert(obj);
return obj->id.device;
}
unsigned int snd_control_get_subdevice(const snd_control_t *obj)
{
assert(obj);
return obj->id.subdevice;
}
const char *snd_control_get_name(const snd_control_t *obj)
{
assert(obj);
return obj->id.name;
}
unsigned int snd_control_get_index(const snd_control_t *obj)
{
assert(obj);
return obj->id.index;
}
void snd_control_set_id(snd_control_t *obj, const snd_control_id_t *ptr)
{
assert(obj && ptr);
obj->id = *ptr;
}
void snd_control_set_numid(snd_control_t *obj, unsigned int val)
{
assert(obj);
obj->id.numid = val;
}
void snd_control_set_interface(snd_control_t *obj, snd_control_iface_t val)
{
assert(obj);
obj->id.iface = snd_enum_to_int(val);
}
void snd_control_set_device(snd_control_t *obj, unsigned int val)
{
assert(obj);
obj->id.device = val;
}
void snd_control_set_subdevice(snd_control_t *obj, unsigned int val)
{
assert(obj);
obj->id.subdevice = val;
}
void snd_control_set_name(snd_control_t *obj, const char *val)
{
assert(obj);
strncpy(obj->id.name, val, sizeof(obj->id.name));
}
void snd_control_set_index(snd_control_t *obj, unsigned int val)
{
assert(obj);
obj->id.index = val;
}
long snd_control_get_boolean(const snd_control_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_control_get_integer(const snd_control_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_control_get_enumerated(const snd_control_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_control_get_byte(const snd_control_t *obj, unsigned int idx)
{
assert(obj);
assert(idx < sizeof(obj->value.bytes.data));
return obj->value.bytes.data[idx];
}
void snd_control_set_boolean(snd_control_t *obj, unsigned int idx, long val)
{
assert(obj);
obj->value.integer.value[idx] = val;
}
void snd_control_set_integer(snd_control_t *obj, unsigned int idx, long val)
{
assert(obj);
obj->value.integer.value[idx] = val;
}
void snd_control_set_enumerated(snd_control_t *obj, unsigned int idx, unsigned int val)
{
assert(obj);
obj->value.enumerated.item[idx] = val;
}
void snd_control_set_byte(snd_control_t *obj, unsigned int idx, unsigned char val)
{
assert(obj);
obj->value.bytes.data[idx] = val;
}
const void * snd_control_get_bytes(const snd_control_t *obj)
{
assert(obj);
return obj->value.bytes.data;
}
void snd_control_get_iec958(const snd_control_t *obj, snd_aes_iec958_t *ptr)
{
assert(obj && ptr);
*ptr = obj->value.iec958;
}
void snd_control_set_iec958(snd_control_t *obj, const snd_aes_iec958_t *ptr)
{
assert(obj && ptr);
obj->value.iec958 = *ptr;
}
size_t snd_hcontrol_list_sizeof()
{
return sizeof(snd_hcontrol_list_t);
}
int snd_hcontrol_list_malloc(snd_hcontrol_list_t **ptr)
{
assert(ptr);
*ptr = calloc(1, sizeof(snd_hcontrol_list_t));
if (!*ptr)
return -ENOMEM;
return 0;
}
void snd_hcontrol_list_free(snd_hcontrol_list_t *obj)
{
free(obj);
}
void snd_hcontrol_list_copy(snd_hcontrol_list_t *dst, const snd_hcontrol_list_t *src)
{
assert(dst && src);
*dst = *src;
}
void snd_hcontrol_list_set_offset(snd_hcontrol_list_t *obj, unsigned int val)
{
assert(obj);
obj->offset = val;
}
unsigned int snd_hcontrol_list_get_used(const snd_hcontrol_list_t *obj)
{
assert(obj);
return obj->used;
}
unsigned int snd_hcontrol_list_get_count(const snd_hcontrol_list_t *obj)
{
assert(obj);
return obj->count;
}
void snd_hcontrol_list_get_id(const snd_hcontrol_list_t *obj, unsigned int idx, snd_control_id_t *ptr)
{
assert(obj && ptr);
assert(idx < obj->used);
*ptr = obj->pids[idx];
}
unsigned int snd_hcontrol_list_get_numid(const snd_hcontrol_list_t *obj, unsigned int idx)
{
assert(obj);
assert(idx < obj->used);
return obj->pids[idx].numid;
}
snd_control_iface_t snd_hcontrol_list_get_interface(const snd_hcontrol_list_t *obj, unsigned int idx)
{
assert(obj);
assert(idx < obj->used);
return snd_int_to_enum(obj->pids[idx].iface);
}
unsigned int snd_hcontrol_list_get_device(const snd_hcontrol_list_t *obj, unsigned int idx)
{
assert(obj);
assert(idx < obj->used);
return obj->pids[idx].device;
}
unsigned int snd_hcontrol_list_get_subdevice(const snd_hcontrol_list_t *obj, unsigned int idx)
{
assert(obj);
assert(idx < obj->used);
return obj->pids[idx].subdevice;
}
const char *snd_hcontrol_list_get_name(const snd_hcontrol_list_t *obj, unsigned int idx)
{
assert(obj);
assert(idx < obj->used);
return obj->pids[idx].name;
}
unsigned int snd_hcontrol_list_get_index(const snd_hcontrol_list_t *obj, unsigned int idx)
{
assert(obj);
assert(idx < obj->used);
return obj->pids[idx].index;
}
size_t snd_hcontrol_sizeof()
{
return sizeof(snd_hcontrol_t);
}
int snd_hcontrol_malloc(snd_hcontrol_t **ptr)
{
assert(ptr);
*ptr = calloc(1, sizeof(snd_hcontrol_t));
if (!*ptr)
return -ENOMEM;
return 0;
}
void snd_hcontrol_free(snd_hcontrol_t *obj)
{
free(obj);
}
void snd_hcontrol_copy(snd_hcontrol_t *dst, const snd_hcontrol_t *src)
{
assert(dst && src);
*dst = *src;
}
void snd_hcontrol_get_id(const snd_hcontrol_t *obj, snd_control_id_t *ptr)
{
assert(obj && ptr);
*ptr = obj->id;
}
unsigned int snd_hcontrol_get_numid(const snd_hcontrol_t *obj)
{
assert(obj);
return obj->id.numid;
}
snd_control_iface_t snd_hcontrol_get_interface(const snd_hcontrol_t *obj)
{
assert(obj);
return snd_int_to_enum(obj->id.iface);
}
unsigned int snd_hcontrol_get_device(const snd_hcontrol_t *obj)
{
assert(obj);
return obj->id.device;
}
unsigned int snd_hcontrol_get_subdevice(const snd_hcontrol_t *obj)
{
assert(obj);
return obj->id.subdevice;
}
const char *snd_hcontrol_get_name(const snd_hcontrol_t *obj)
{
assert(obj);
return obj->id.name;
}
unsigned int snd_hcontrol_get_index(const snd_hcontrol_t *obj)
{
assert(obj);
return obj->id.index;
}
void snd_hcontrol_set_callback_change(snd_hcontrol_t *obj, snd_hcontrol_callback_t val)
{
assert(obj);
obj->callback_change = val;
}
void snd_hcontrol_set_callback_value(snd_hcontrol_t *obj, snd_hcontrol_callback_t val)
{
assert(obj);
obj->callback_value = val;
}
void snd_hcontrol_set_callback_remove(snd_hcontrol_t *obj, snd_hcontrol_callback_t val)
{
assert(obj);
obj->callback_remove = val;
}
void * snd_hcontrol_get_private_data(const snd_hcontrol_t *obj)
{
assert(obj);
return obj->private_data;
}
void snd_hcontrol_set_private_data(snd_hcontrol_t *obj, void * val)
{
assert(obj);
obj->private_data = val;
}
void snd_hcontrol_set_private_free(snd_hcontrol_t *obj, snd_hcontrol_private_free_t val)
{
assert(obj);
obj->private_free = val;
}

View file

@ -24,7 +24,6 @@
#include <stddef.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/shm.h>
#include <sys/socket.h>
@ -107,13 +106,13 @@ 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_hw_info_t *info)
static int snd_ctl_shm_hw_info(snd_ctl_t *ctl, snd_ctl_info_t *info)
{
snd_ctl_shm_t *shm = ctl->private;
volatile snd_ctl_shm_ctrl_t *ctrl = shm->ctrl;
int err;
// ctrl->u.hw_info = *info;
ctrl->cmd = SNDRV_CTL_IOCTL_HW_INFO;
ctrl->cmd = SNDRV_CTL_IOCTL_INFO;
err = snd_ctl_shm_action(ctl);
if (err < 0)
return err;
@ -126,7 +125,7 @@ static int snd_ctl_shm_clist(snd_ctl_t *ctl, snd_control_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->controls_request * sizeof(*list->pids);
size_t bytes = list->space * sizeof(*list->pids);
int err;
snd_control_id_t *pids = list->pids;
if (bytes > maxsize)
@ -138,6 +137,7 @@ static int snd_ctl_shm_clist(snd_ctl_t *ctl, snd_control_list_t *list)
return err;
*list = ctrl->u.clist;
list->pids = pids;
bytes = list->used * sizeof(*list->pids);
memcpy(pids, (void *)ctrl->data, bytes);
return err;
}
@ -369,7 +369,7 @@ static int make_inet_socket(const char *host, int port)
}
#endif
int snd_ctl_shm_open(snd_ctl_t **handlep, char *name, char *socket, char *sname)
int snd_ctl_shm_open(snd_ctl_t **handlep, const char *name, const char *socket, const char *sname)
{
snd_ctl_t *ctl;
snd_ctl_shm_t *shm = NULL;
@ -469,11 +469,11 @@ 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;
char *server = NULL;
char *sname = NULL;
const char *server = NULL;
const char *sname = NULL;
snd_config_t *sconfig;
char *host = NULL;
char *socket = NULL;
const char *host = NULL;
const char *socket = NULL;
long port = -1;
int err;
int local;

View file

@ -23,17 +23,15 @@
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <assert.h>
#define __USE_GNU
#include <search.h>
#include "control_local.h"
static void snd_ctl_hfree1(snd_hcontrol_t *hcontrol);
int snd_ctl_hbuild(snd_ctl_t *handle, snd_ctl_hsort_t *hsort)
int snd_ctl_hbuild(snd_ctl_t *handle, snd_ctl_hsort_t hsort)
{
snd_control_list_t list;
snd_hcontrol_t *hcontrol, *prev;
@ -49,21 +47,20 @@ int snd_ctl_hbuild(snd_ctl_t *handle, snd_ctl_hsort_t *hsort)
do {
if (list.pids != NULL)
free(list.pids);
list.controls_offset = 0;
list.controls_request = 0;
list.controls_count = 0;
list.offset = 0;
list.space = 0;
if ((err = snd_ctl_clist(handle, &list)) < 0)
return err;
if (list.controls == 0)
if (list.count == 0)
break;
list.pids = (snd_control_id_t *)calloc(list.controls, sizeof(snd_control_id_t));
list.pids = (snd_control_id_t *)calloc(list.count, sizeof(snd_control_id_t));
if (list.pids == NULL)
return -ENOMEM;
list.controls_request = list.controls;
list.space = list.count;
if ((err = snd_ctl_clist(handle, &list)) < 0)
return err;
} while (list.controls != list.controls_count);
for (idx = 0, prev = NULL; idx < list.controls_count; idx++) {
} 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)
goto __nomem;
@ -101,10 +98,10 @@ static void snd_ctl_hfree1(snd_hcontrol_t *hcontrol)
handle = hcontrol->handle;
assert(handle != NULL);
assert(handle->hcount > 0);
if (hcontrol->event_remove)
hcontrol->event_remove(handle, hcontrol);
if (hcontrol->callback_remove)
hcontrol->callback_remove(handle, hcontrol);
if (hcontrol->private_free)
hcontrol->private_free(hcontrol->private_data);
hcontrol->private_free(hcontrol);
list_del(&hcontrol->list);
free(hcontrol);
handle->hcount--;
@ -236,7 +233,7 @@ static void snd_ctl_hresort_free(snd_hcontrol_t *hcontrol ATTRIBUTE_UNUSED)
/* nothing */
}
int snd_ctl_hresort(snd_ctl_t *handle, snd_ctl_hsort_t *hsort)
int snd_ctl_hresort(snd_ctl_t *handle, snd_ctl_hsort_t hsort)
{
struct list_head *list;
snd_hcontrol_t *hcontrol;
@ -336,21 +333,21 @@ int snd_ctl_hlist(snd_ctl_t *handle, snd_hcontrol_list_t *hlist)
unsigned int idx;
assert(hlist != NULL);
if (hlist->controls_offset >= (unsigned int)handle->hcount)
if (hlist->offset >= (unsigned int)handle->hcount)
return -EINVAL;
hlist->controls_count = 0;
hlist->controls = handle->hcount;
if (hlist->controls_request > 0) {
hlist->used = 0;
hlist->count = handle->hcount;
if (hlist->space > 0) {
if (hlist->pids == NULL)
return -EINVAL;
idx = 0;
list_for_each(list, &handle->hlist) {
hcontrol = list_entry(list, snd_hcontrol_t, list);
if (idx >= hlist->controls_offset + hlist->controls_request)
if (idx >= hlist->offset + hlist->space)
break;
if (idx >= hlist->controls_offset) {
if (idx >= hlist->offset) {
hlist->pids[idx] = hcontrol->id;
hlist->controls_count++;
hlist->used++;
}
idx++;
}
@ -358,7 +355,7 @@ int snd_ctl_hlist(snd_ctl_t *handle, snd_hcontrol_list_t *hlist)
return 0;
}
int snd_ctl_hcallback_rebuild(snd_ctl_t *handle, snd_ctl_hcallback_rebuild_t *callback, void *private_data)
int snd_ctl_hcallback_rebuild(snd_ctl_t *handle, snd_ctl_hcallback_rebuild_t callback, void *private_data)
{
assert(handle != NULL);
handle->callback_rebuild = callback;
@ -366,7 +363,7 @@ int snd_ctl_hcallback_rebuild(snd_ctl_t *handle, snd_ctl_hcallback_rebuild_t *ca
return 0;
}
int snd_ctl_hcallback_add(snd_ctl_t *handle, snd_ctl_hcallback_add_t *callback, void *private_data)
int snd_ctl_hcallback_add(snd_ctl_t *handle, snd_ctl_hcallback_add_t callback, void *private_data)
{
assert(handle != NULL);
handle->callback_add = callback;
@ -476,14 +473,31 @@ int snd_ctl_hevent(snd_ctl_t *handle)
return handle->herr;
list_for_each(list, &handle->hlist) {
hcontrol = list_entry(list, snd_hcontrol_t, list);
if (hcontrol->change && hcontrol->event_change) {
hcontrol->event_change(hcontrol->handle, hcontrol);
if (hcontrol->change && hcontrol->callback_change) {
hcontrol->callback_change(hcontrol->handle, hcontrol);
hcontrol->change = 0;
}
if (hcontrol->value && hcontrol->event_value) {
hcontrol->event_value(hcontrol->handle, hcontrol);
if (hcontrol->value && hcontrol->callback_value) {
hcontrol->callback_value(hcontrol->handle, hcontrol);
hcontrol->value = 0;
}
}
return res;
}
int snd_hcontrol_list_alloc_space(snd_hcontrol_list_t *obj, unsigned int entries)
{
obj->pids = calloc(entries, sizeof(*obj->pids));
if (!obj->pids) {
obj->space = 0;
return -ENOMEM;
}
obj->space = entries;
return 0;
}
void snd_hcontrol_list_free_space(snd_hcontrol_list_t *obj)
{
free(obj->pids);
obj->pids = NULL;
}

View file

@ -21,7 +21,6 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "local.h"
static int defaults_card(const char *env)