Updated the hctl interface (the more independent way).

This commit is contained in:
Jaroslav Kysela 2001-02-09 14:50:05 +00:00
parent 3e561540d5
commit 38033b49dd
10 changed files with 250 additions and 177 deletions

View file

@ -196,33 +196,39 @@ void snd_ctl_elem_list_free_space(snd_ctl_elem_list_t *obj);
typedef struct _snd_hctl_elem snd_hctl_elem_t;
typedef struct _snd_hctl snd_hctl_t;
#ifdef __cplusplus
extern "C" {
#endif
typedef int (*snd_hctl_compare_t)(const snd_hctl_elem_t *e1,
const snd_hctl_elem_t *e2);
typedef int (*snd_hctl_callback_t)(snd_ctl_t *ctl,
typedef int (*snd_hctl_callback_t)(snd_hctl_t *hctl,
snd_ctl_event_type_t event,
snd_hctl_elem_t *elem);
typedef int (*snd_hctl_elem_callback_t)(snd_hctl_elem_t *elem,
snd_ctl_event_type_t event);
snd_ctl_event_type_t event);
int snd_hctl_build(snd_ctl_t *ctl);
snd_hctl_elem_t *snd_hctl_first_elem(snd_ctl_t *ctl);
snd_hctl_elem_t *snd_hctl_last_elem(snd_ctl_t *ctl);
int snd_hctl_open(snd_hctl_t **hctl, char *name);
int snd_hctl_close(snd_hctl_t *hctl);
int snd_hctl_nonblock(snd_hctl_t *hctl, int nonblock);
int snd_hctl_async(snd_hctl_t *hctl, int sig, pid_t pid);
int snd_hctl_poll_descriptor(snd_hctl_t *hctl);
snd_hctl_elem_t *snd_hctl_first_elem(snd_hctl_t *hctl);
snd_hctl_elem_t *snd_hctl_last_elem(snd_hctl_t *hctl);
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);
int snd_hctl_elem_info(snd_hctl_elem_t *elem, snd_ctl_elem_info_t *info);
int snd_hctl_elem_info(snd_hctl_elem_t *elem, snd_ctl_elem_info_t * info);
int snd_hctl_elem_read(snd_hctl_elem_t *elem, snd_ctl_elem_t * value);
int snd_hctl_elem_write(snd_hctl_elem_t *elem, snd_ctl_elem_t * value);
unsigned int snd_hctl_get_count(snd_ctl_t *ctl);
snd_hctl_elem_t *snd_hctl_find_elem(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id);
void snd_hctl_set_callback(snd_ctl_t *ctl, snd_hctl_callback_t callback);
void snd_hctl_set_callback_private(snd_ctl_t *ctl, void *private);
void *snd_hctl_get_callback_private(snd_ctl_t *ctl);
int snd_hctl_event(snd_ctl_t *ctl, snd_ctl_event_t *event);
int snd_hctl_events(snd_ctl_t *ctl);
unsigned int snd_hctl_get_count(snd_hctl_t *ctl);
snd_hctl_elem_t *snd_hctl_find_elem(snd_hctl_t *ctl, const snd_ctl_elem_id_t *id);
void snd_hctl_set_callback(snd_hctl_t *ctl, snd_hctl_callback_t callback);
void snd_hctl_set_callback_private(snd_hctl_t *ctl, void *private);
void *snd_hctl_get_callback_private(snd_hctl_t *ctl);
int snd_hctl_event(snd_hctl_t *ctl, snd_ctl_event_t *event);
int snd_hctl_events(snd_hctl_t *ctl);
#ifdef __cplusplus
}

View file

@ -12,7 +12,7 @@ typedef int (*snd_mixer_callback_t)(snd_mixer_t *ctl,
snd_ctl_event_type_t event,
snd_mixer_elem_t *elem);
typedef int (*snd_mixer_elem_callback_t)(snd_mixer_elem_t *elem,
snd_ctl_event_type_t event);
snd_ctl_event_type_t event);
enum _snd_mixer_elem_type {
SND_MIXER_ELEM_SIMPLE,

View file

@ -39,7 +39,6 @@ int snd_ctl_close(snd_ctl_t *ctl)
int res;
assert(ctl);
res = ctl->ops->close(ctl);
snd_hctl_free(ctl);
free(ctl);
return res;
}

View file

@ -289,7 +289,6 @@ int snd_ctl_hw_open(snd_ctl_t **handle, const char *name, int card)
ctl->type = SND_CTL_TYPE_HW;
ctl->ops = &snd_ctl_hw_ops;
ctl->private = hw;
INIT_LIST_HEAD(&ctl->hlist);
*handle = ctl;
return 0;
}

View file

@ -50,7 +50,21 @@ struct _snd_ctl {
snd_ctl_ops_t *ops;
void *private;
int nonblock;
struct list_head hlist; /* list of all controls */
};
struct _snd_hctl_elem {
snd_ctl_elem_id_t id; /* must be always on top */
struct list_head list; /* links for list of all helems */
/* event callback */
snd_hctl_elem_callback_t callback;
void *callback_private;
/* links */
snd_hctl_t *hctl; /* associated handle */
};
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;
@ -59,20 +73,6 @@ struct _snd_ctl {
void *callback_private;
};
struct _snd_hctl_elem {
snd_ctl_elem_id_t id; /* must be always on top */
struct list_head list; /* links for list of all helems */
/* event callback */
snd_hctl_elem_callback_t callback;
void *callback_private;
/* links */
snd_ctl_t *ctl; /* 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);
int snd_hctl_free(snd_ctl_t *ctl);
int snd_hctl_compare_default(const snd_hctl_elem_t *c1,
const snd_hctl_elem_t *c2);

View file

@ -475,7 +475,6 @@ int snd_ctl_shm_open(snd_ctl_t **handlep, const char *name, const char *socket,
ctl->type = SND_CTL_TYPE_SHM;
ctl->ops = &snd_ctl_shm_ops;
ctl->private = shm;
INIT_LIST_HEAD(&ctl->hlist);
*handlep = ctl;
return 0;

View file

@ -29,18 +29,77 @@
#define __USE_GNU
#include "control_local.h"
static int _snd_hctl_find_elem(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id, int *dir)
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)
{
snd_hctl_t *hctl;
snd_ctl_t *ctl;
int err;
assert(hctlp);
*hctlp = NULL;
if ((err = snd_ctl_open(&ctl, name)) < 0)
return err;
if ((hctl = (snd_hctl_t *)calloc(1, sizeof(snd_hctl_t))) == NULL) {
snd_ctl_close(ctl);
return -ENOMEM;
}
INIT_LIST_HEAD(&hctl->hlist);
hctl->ctl = ctl;
if ((err = snd_hctl_build(hctl)) < 0) {
snd_hctl_close(hctl);
return err;
}
*hctlp = hctl;
return 0;
}
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;
}
int snd_hctl_nonblock(snd_hctl_t *hctl, int nonblock)
{
assert(hctl && hctl->ctl);
return snd_ctl_nonblock(hctl->ctl, nonblock);
}
int snd_hctl_async(snd_hctl_t *hctl, int sig, pid_t pid)
{
assert(hctl && hctl->ctl);
return snd_ctl_async(hctl->ctl, sig, pid);
}
int snd_hctl_poll_descriptor(snd_hctl_t *hctl)
{
assert(hctl && hctl->ctl);
return snd_ctl_poll_descriptor(hctl->ctl);
}
static int _snd_hctl_find_elem(snd_hctl_t *hctl, const snd_ctl_elem_id_t *id, int *dir)
{
unsigned int l, u;
int c = 0;
int idx = -1;
assert(ctl && id);
assert(ctl->hcompare);
assert(hctl && id);
assert(hctl->hcompare);
l = 0;
u = ctl->hcount;
u = hctl->hcount;
while (l < u) {
idx = (l + u) / 2;
c = ctl->hcompare((snd_hctl_elem_t *) id, ctl->helems[idx]);
c = hctl->hcompare((snd_hctl_elem_t *) id, hctl->helems[idx]);
if (c < 0)
u = idx;
else if (c > 0)
@ -52,89 +111,88 @@ static int _snd_hctl_find_elem(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id, int
return idx;
}
static int snd_hctl_elem_add(snd_ctl_t *ctl, snd_hctl_elem_t *elem)
static int snd_hctl_elem_add(snd_hctl_t *hctl, snd_hctl_elem_t *elem)
{
int dir;
int idx;
if (ctl->hcount == ctl->halloc) {
if (hctl->hcount == hctl->halloc) {
snd_hctl_elem_t **h;
ctl->halloc += 32;
h = realloc(ctl->helems, sizeof(*h) * ctl->halloc);
hctl->halloc += 32;
h = realloc(hctl->helems, sizeof(*h) * hctl->halloc);
if (!h)
return -ENOMEM;
ctl->helems = h;
hctl->helems = h;
}
if (ctl->hcount == 0) {
list_add_tail(&elem->list, &ctl->hlist);
ctl->helems[0] = elem;
if (hctl->hcount == 0) {
list_add_tail(&elem->list, &hctl->hlist);
hctl->helems[0] = elem;
} else {
idx = _snd_hctl_find_elem(ctl, &elem->id, &dir);
idx = _snd_hctl_find_elem(hctl, &elem->id, &dir);
assert(dir != 0);
if (dir > 0) {
list_add(&elem->list, &ctl->helems[idx]->list);
list_add(&elem->list, &hctl->helems[idx]->list);
} else {
list_add_tail(&elem->list, &ctl->helems[idx]->list);
list_add_tail(&elem->list, &hctl->helems[idx]->list);
idx++;
}
memmove(ctl->helems + idx + 1,
ctl->helems + idx,
ctl->hcount - idx);
memmove(hctl->helems + idx + 1,
hctl->helems + idx,
hctl->hcount - idx);
}
ctl->hcount++;
if (ctl->callback) {
int res = ctl->callback(ctl, SND_CTL_EVENT_ADD, elem);
hctl->hcount++;
if (hctl->callback) {
int res = hctl->callback(hctl, SND_CTL_EVENT_ADD, elem);
if (res < 0)
return res;
}
return 0;
}
static void snd_hctl_elem_remove(snd_ctl_t *ctl, unsigned int idx)
static void snd_hctl_elem_remove(snd_hctl_t *hctl, unsigned int idx)
{
snd_hctl_elem_t *elem = ctl->helems[idx];
snd_hctl_elem_t *elem = hctl->helems[idx];
unsigned int m;
if (elem->callback)
elem->callback(elem, SND_CTL_EVENT_REMOVE);
list_del(&elem->list);
free(elem);
ctl->hcount--;
m = ctl->hcount - idx;
hctl->hcount--;
m = hctl->hcount - idx;
if (m > 0)
memmove(ctl->helems + idx, ctl->helems + idx + 1, m);
memmove(hctl->helems + idx, hctl->helems + idx + 1, m);
}
int snd_hctl_free(snd_ctl_t *ctl)
static int snd_hctl_free(snd_hctl_t *hctl)
{
while (ctl->hcount > 0)
snd_hctl_elem_remove(ctl, ctl->hcount - 1);
free(ctl->helems);
ctl->helems = 0;
ctl->halloc = 0;
INIT_LIST_HEAD(&ctl->hlist);
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);
return 0;
}
static void snd_hctl_sort(snd_ctl_t *ctl)
static void snd_hctl_sort(snd_hctl_t *hctl)
{
unsigned int k;
int compar(const void *a, const void *b) {
return ctl->hcompare(*(const snd_hctl_elem_t **) a,
*(const snd_hctl_elem_t **) b);
return hctl->hcompare(*(const snd_hctl_elem_t **) a,
*(const snd_hctl_elem_t **) b);
}
assert(ctl);
assert(ctl->hcompare);
INIT_LIST_HEAD(&ctl->hlist);
qsort(ctl->helems, ctl->hcount, sizeof(*ctl->helems), compar);
for (k = 0; k < ctl->hcount; k++)
list_add_tail(&ctl->helems[k]->list, &ctl->hlist);
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);
}
void snd_hctl_set_compare(snd_ctl_t *ctl, snd_hctl_compare_t hsort)
void snd_hctl_set_compare(snd_hctl_t *hctl, snd_hctl_compare_t hsort)
{
assert(ctl);
ctl->hcompare = hsort;
snd_hctl_sort(ctl);
assert(hctl);
hctl->hcompare = hsort == NULL ? snd_hctl_compare_default : hsort;
snd_hctl_sort(hctl);
}
#define NOT_FOUND 1000000000
@ -225,8 +283,8 @@ int snd_hctl_compare_fast(const snd_hctl_elem_t *c1,
return c1->id.numid - c2->id.numid;
}
int snd_hctl_compare_default(const snd_hctl_elem_t *c1,
const snd_hctl_elem_t *c2)
static int snd_hctl_compare_default(const snd_hctl_elem_t *c1,
const snd_hctl_elem_t *c2)
{
int res, p1, p2;
int d = c1->id.iface - c2->id.iface;
@ -246,26 +304,26 @@ int snd_hctl_compare_default(const snd_hctl_elem_t *c1,
return d;
}
snd_hctl_elem_t *snd_hctl_first_elem(snd_ctl_t *ctl)
snd_hctl_elem_t *snd_hctl_first_elem(snd_hctl_t *hctl)
{
assert(ctl);
if (list_empty(&ctl->hlist))
assert(hctl);
if (list_empty(&hctl->hlist))
return NULL;
return list_entry(ctl->hlist.next, snd_hctl_elem_t, list);
return list_entry(hctl->hlist.next, snd_hctl_elem_t, list);
}
snd_hctl_elem_t *snd_hctl_last_elem(snd_ctl_t *ctl)
snd_hctl_elem_t *snd_hctl_last_elem(snd_hctl_t *hctl)
{
assert(ctl);
if (list_empty(&ctl->hlist))
assert(hctl);
if (list_empty(&hctl->hlist))
return NULL;
return list_entry(ctl->hlist.prev, snd_hctl_elem_t, list);
return list_entry(hctl->hlist.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->ctl->hlist)
if (elem->list.next == &elem->hctl->hlist)
return NULL;
return list_entry(elem->list.next, snd_hctl_elem_t, list);
}
@ -273,44 +331,45 @@ 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->ctl->hlist)
if (elem->list.prev == &elem->hctl->hlist)
return NULL;
return list_entry(elem->list.prev, snd_hctl_elem_t, list);
}
snd_hctl_elem_t *snd_hctl_find_elem(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id)
snd_hctl_elem_t *snd_hctl_find_elem(snd_hctl_t *hctl, const snd_ctl_elem_id_t *id)
{
int dir;
int res = _snd_hctl_find_elem(ctl, id, &dir);
int res = _snd_hctl_find_elem(hctl, id, &dir);
if (res < 0 || dir != 0)
return NULL;
return ctl->helems[res];
return hctl->helems[res];
}
int snd_hctl_build(snd_ctl_t *ctl)
static int snd_hctl_build(snd_hctl_t *hctl)
{
snd_ctl_elem_list_t list;
int err = 0;
unsigned int idx;
assert(ctl);
assert(ctl->hcount == 0);
assert(list_empty(&ctl->hlist));
assert(hctl);
assert(hctl->ctl);
assert(hctl->hcount == 0);
assert(list_empty(&hctl->hlist));
memset(&list, 0, sizeof(list));
if ((err = snd_ctl_elem_list(ctl, &list)) < 0)
if ((err = snd_ctl_elem_list(hctl->ctl, &list)) < 0)
goto _end;
while (list.count != list.used) {
err = snd_ctl_elem_list_alloc_space(&list, list.count);
if (err < 0)
goto _end;
if ((err = snd_ctl_elem_list(ctl, &list)) < 0)
if ((err = snd_ctl_elem_list(hctl->ctl, &list)) < 0)
goto _end;
}
if (ctl->halloc < list.count) {
ctl->halloc = list.count;
free(ctl->helems);
ctl->helems = malloc(ctl->halloc * sizeof(*ctl->helems));
if (!ctl->helems) {
if (hctl->halloc < list.count) {
hctl->halloc = list.count;
free(hctl->helems);
hctl->helems = malloc(hctl->halloc * sizeof(*hctl->helems));
if (!hctl->helems) {
err = -ENOMEM;
goto _end;
}
@ -319,23 +378,23 @@ int snd_hctl_build(snd_ctl_t *ctl)
snd_hctl_elem_t *elem;
elem = calloc(1, sizeof(snd_hctl_elem_t));
if (elem == NULL) {
snd_hctl_free(ctl);
snd_hctl_free(hctl);
err = -ENOMEM;
goto _end;
}
elem->id = list.pids[idx];
elem->ctl = ctl;
ctl->helems[idx] = elem;
list_add_tail(&elem->list, &ctl->hlist);
ctl->hcount++;
elem->hctl = hctl;
hctl->helems[idx] = elem;
list_add_tail(&elem->list, &hctl->hlist);
hctl->hcount++;
}
if (!ctl->hcompare)
ctl->hcompare = snd_hctl_compare_default;
snd_hctl_sort(ctl);
if (ctl->callback) {
for (idx = 0; idx < ctl->hcount; idx++) {
int res = ctl->callback(ctl, SND_CTL_EVENT_ADD,
ctl->helems[idx]);
if (!hctl->hcompare)
hctl->hcompare = 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;
}
@ -346,49 +405,50 @@ int snd_hctl_build(snd_ctl_t *ctl)
return err;
}
void snd_hctl_set_callback(snd_ctl_t *ctl, snd_hctl_callback_t callback)
void snd_hctl_set_callback(snd_hctl_t *hctl, snd_hctl_callback_t callback)
{
assert(ctl);
ctl->callback = callback;
assert(hctl);
hctl->callback = callback;
}
void snd_hctl_set_callback_private(snd_ctl_t *ctl, void *callback_private)
void snd_hctl_set_callback_private(snd_hctl_t *hctl, void *callback_private)
{
assert(ctl);
ctl->callback_private = callback_private;
assert(hctl);
hctl->callback_private = callback_private;
}
void *snd_hctl_get_callback_private(snd_ctl_t *ctl)
void *snd_hctl_get_callback_private(snd_hctl_t *hctl)
{
assert(ctl);
return ctl->callback_private;
assert(hctl);
return hctl->callback_private;
}
unsigned int snd_hctl_get_count(snd_ctl_t *ctl)
unsigned int snd_hctl_get_count(snd_hctl_t *hctl)
{
return ctl->hcount;
return hctl->hcount;
}
int snd_hctl_event(snd_ctl_t *ctl, snd_ctl_event_t *event)
int snd_hctl_event(snd_hctl_t *hctl, snd_ctl_event_t *event)
{
snd_hctl_elem_t *elem;
int res;
assert(ctl);
assert(hctl);
assert(hctl->ctl);
switch (event->type) {
case SND_CTL_EVENT_REMOVE:
{
int dir;
res = _snd_hctl_find_elem(ctl, &event->data.id, &dir);
res = _snd_hctl_find_elem(hctl, &event->data.id, &dir);
assert(res >= 0 && dir == 0);
if (res < 0 || dir != 0)
return -ENOENT;
snd_hctl_elem_remove(ctl, res);
snd_hctl_elem_remove(hctl, res);
break;
}
case SND_CTL_EVENT_VALUE:
case SND_CTL_EVENT_CHANGE:
elem = snd_hctl_find_elem(ctl, &event->data.id);
elem = snd_hctl_find_elem(hctl, &event->data.id);
assert(elem);
if (!elem)
return -ENOENT;
@ -403,16 +463,16 @@ int snd_hctl_event(snd_ctl_t *ctl, snd_ctl_event_t *event)
if (elem == NULL)
return -ENOMEM;
elem->id = event->data.id;
elem->ctl = ctl;
res = snd_hctl_elem_add(ctl, elem);
elem->hctl = hctl;
res = snd_hctl_elem_add(hctl, elem);
if (res < 0)
return res;
break;
case SND_CTL_EVENT_REBUILD:
snd_hctl_free(ctl);
res = snd_hctl_build(ctl);
if (ctl->callback) {
res = ctl->callback(ctl, event->type, NULL);
snd_hctl_free(hctl);
res = snd_hctl_build(hctl);
if (hctl->callback) {
res = hctl->callback(hctl, event->type, NULL);
if (res < 0)
return res;
}
@ -424,14 +484,17 @@ int snd_hctl_event(snd_ctl_t *ctl, snd_ctl_event_t *event)
return 0;
}
int snd_hctl_events(snd_ctl_t *ctl)
int snd_hctl_events(snd_hctl_t *hctl)
{
snd_ctl_event_t event;
int res;
while ((res = snd_ctl_read(ctl, &event)) != 0) {
assert(hctl);
assert(hctl->ctl);
while ((res = snd_ctl_read(hctl->ctl, &event)) != 0) {
if (res < 0)
return res;
res = snd_hctl_event(ctl, &event);
res = snd_hctl_event(hctl, &event);
if (res < 0)
return res;
}
@ -440,19 +503,28 @@ int snd_hctl_events(snd_ctl_t *ctl)
int snd_hctl_elem_info(snd_hctl_elem_t *elem, snd_ctl_elem_info_t *info)
{
assert(elem);
assert(elem->hctl);
assert(info);
info->id = elem->id;
return snd_ctl_elem_info(elem->ctl, 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)
{
assert(elem);
assert(elem->hctl);
assert(value);
value->id = elem->id;
return snd_ctl_elem_read(elem->ctl, 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)
{
assert(elem);
assert(elem->hctl);
assert(value);
value->id = elem->id;
return snd_ctl_elem_write(elem->ctl, value);
return snd_ctl_elem_write(elem->hctl->ctl, value);
}

View file

@ -31,17 +31,17 @@
int snd_mixer_open(snd_mixer_t **mixerp, char *name)
{
snd_mixer_t *mixer;
snd_ctl_t *ctl;
snd_hctl_t *hctl;
int err;
assert(mixerp);
if ((err = snd_ctl_open(&ctl, name)) < 0)
if ((err = snd_hctl_open(&hctl, name)) < 0)
return err;
mixer = calloc(1, sizeof(snd_mixer_t));
if (mixer == NULL) {
snd_ctl_close(ctl);
snd_hctl_close(hctl);
return -ENOMEM;
}
mixer->ctl = ctl;
mixer->hctl = hctl;
INIT_LIST_HEAD(&mixer->elems);
*mixerp = mixer;
return 0;
@ -82,14 +82,14 @@ int snd_mixer_close(snd_mixer_t *mixer)
{
assert(mixer);
snd_mixer_free(mixer);
return snd_ctl_close(mixer->ctl);
return snd_hctl_close(mixer->hctl);
}
int snd_mixer_poll_descriptor(snd_mixer_t *mixer)
{
if (mixer == NULL || mixer->ctl == NULL)
if (mixer == NULL || mixer->hctl == NULL)
return -EIO;
return snd_ctl_poll_descriptor(mixer->ctl);
return snd_hctl_poll_descriptor(mixer->hctl);
}
snd_mixer_elem_t *snd_mixer_first_elem(snd_mixer_t *mixer)
@ -126,6 +126,6 @@ snd_mixer_elem_t *snd_mixer_elem_prev(snd_mixer_elem_t *elem)
int snd_mixer_events(snd_mixer_t *mixer)
{
return snd_hctl_events(mixer->ctl);
return snd_hctl_events(mixer->hctl);
}

View file

@ -46,7 +46,7 @@ struct _snd_mixer_elem {
};
struct _snd_mixer {
snd_ctl_t *ctl;
snd_hctl_t *hctl;
struct list_head elems; /* list of all elemss */
unsigned int count;
snd_mixer_callback_t callback;

View file

@ -112,43 +112,43 @@ static snd_hctl_elem_t *test_mixer_id(snd_mixer_t *mixer, const char *name, int
id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
strcpy(id.name, name);
id.index = index;
helem = snd_hctl_find_elem(mixer->ctl, &id);
helem = snd_hctl_find_elem(mixer->hctl, &id);
// fprintf(stderr, "Looking for control: '%s', %i (0x%lx)\n", name, index, (long)helem);
return helem;
}
static int get_mixer_info(snd_mixer_t *mixer, const char *name, int index, snd_ctl_elem_info_t *info)
{
memset(info, 0, sizeof(*info));
info->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
strcpy(info->id.name, name);
info->id.index = index;
return snd_ctl_elem_info(mixer->ctl, info);
snd_hctl_elem_t *helem = test_mixer_id(mixer, name, index);
if (helem == NULL)
return -EINVAL;
return snd_hctl_elem_info(helem, info);
}
static int get_mixer_read(snd_mixer_t *mixer, const char *name, int index, snd_ctl_elem_t *control)
{
memset(control, 0, sizeof(*control));
control->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
strcpy(control->id.name, name);
control->id.index = index;
return snd_ctl_elem_read(mixer->ctl, control);
snd_hctl_elem_t *helem = test_mixer_id(mixer, name, index);
if (helem == NULL)
return -EINVAL;
return snd_hctl_elem_read(helem, control);
}
static int put_mixer_write(snd_mixer_t *mixer, const char *name, int index, snd_ctl_elem_t *control)
{
snd_hctl_elem_t *helem = test_mixer_id(mixer, name, index);
if (helem == NULL)
return -EINVAL;
control->id.numid = 0;
control->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
strcpy(control->id.name, name);
control->id.device = control->id.subdevice = 0;
control->id.index = index;
control->indirect = 0;
memset(&control->reserved, 0, sizeof(control->reserved));
return snd_ctl_elem_write(mixer->ctl, control);
return snd_hctl_elem_write(helem, control);
}
static int hctl_elem_event(snd_hctl_elem_t *helem,
snd_ctl_event_type_t type)
snd_ctl_event_type_t type)
{
switch (type) {
case SND_CTL_EVENT_CHANGE:
@ -694,7 +694,7 @@ static int build_elem(snd_mixer_t *mixer, const char *sname)
hctl_elem_add(simple, helem);
} else for (capture_item = 1; capture_item < csource_info.value.enumerated.items; capture_item++) {
csource_info.value.enumerated.item = capture_item;
if ((err = snd_ctl_elem_info(mixer->ctl, &csource_info)) < 0)
if ((err = snd_hctl_elem_info(helem, &csource_info)) < 0)
return err;
if (!strcmp(csource_info.value.enumerated.name, str)) {
if (voices < csource_info.count)
@ -783,11 +783,11 @@ static int build_elem(snd_mixer_t *mixer, const char *sname)
return 0;
}
int mixer_simple_ctl_callback(snd_ctl_t *ctl,
int mixer_simple_ctl_callback(snd_hctl_t *hctl,
snd_ctl_event_type_t event,
snd_hctl_elem_t *elem ATTRIBUTE_UNUSED)
{
snd_mixer_t *mixer = snd_hctl_get_callback_private(ctl);
snd_mixer_t *mixer = snd_hctl_get_callback_private(hctl);
int err;
switch (event) {
case SND_CTL_EVENT_REBUILD:
@ -835,19 +835,17 @@ int snd_mixer_simple_build(snd_mixer_t *mixer)
"Capture Boost",
NULL
};
snd_ctl_t *ctl = mixer->ctl;
snd_hctl_t *hctl = mixer->hctl;
char **elem = elems;
int err;
if ((err = snd_hctl_build(ctl)) < 0)
return err;
while (*elem) {
if ((err = build_elem(mixer, *elem)) < 0)
return err;
elem++;
}
snd_hctl_set_callback(ctl, mixer_simple_ctl_callback);
snd_hctl_set_callback_private(ctl, mixer);
snd_hctl_set_callback(hctl, mixer_simple_ctl_callback);
snd_hctl_set_callback_private(hctl, mixer);
return 0;
}