mirror of
https://github.com/alsa-project/alsa-utils
synced 2024-11-10 03:25:43 +01:00
alsactl: obsolete array for maintenance of handlers
In former commits, handlers of control node are maintained by link list, instead of one-dimensional array. This commit obsoletes the array and split source preparation to a function. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
parent
89ab7146ba
commit
af14a2fab0
1 changed files with 33 additions and 32 deletions
|
@ -35,8 +35,6 @@ struct src_entry {
|
||||||
struct list_head list;
|
struct list_head list;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MAX_CARDS 256
|
|
||||||
|
|
||||||
struct snd_card_iterator {
|
struct snd_card_iterator {
|
||||||
int card;
|
int card;
|
||||||
char name[16];
|
char name[16];
|
||||||
|
@ -54,11 +52,6 @@ static const char *snd_card_iterator_next(struct snd_card_iterator *iter)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (iter->card < 0)
|
if (iter->card < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (iter->card >= MAX_CARDS) {
|
|
||||||
fprintf(stderr, "alsactl: too many cards\n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
snprintf(iter->name, sizeof(iter->name), "hw:%d", iter->card);
|
snprintf(iter->name, sizeof(iter->name), "hw:%d", iter->card);
|
||||||
|
|
||||||
|
@ -140,6 +133,36 @@ static int open_ctl(const char *name, snd_ctl_t **ctlp)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int prepare_source_entry(struct list_head *srcs, const char *name)
|
||||||
|
{
|
||||||
|
snd_ctl_t *handle;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
if (!name) {
|
||||||
|
struct snd_card_iterator iter;
|
||||||
|
const char *cardname;
|
||||||
|
|
||||||
|
snd_card_iterator_init(&iter);
|
||||||
|
while ((cardname = snd_card_iterator_next(&iter))) {
|
||||||
|
err = open_ctl(cardname, &handle);
|
||||||
|
if (err < 0)
|
||||||
|
return err;
|
||||||
|
err = insert_source_entry(srcs, handle, cardname);
|
||||||
|
if (err < 0)
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
err = open_ctl(name, &handle);
|
||||||
|
if (err < 0)
|
||||||
|
return err;
|
||||||
|
err = insert_source_entry(srcs, handle, name);
|
||||||
|
if (err < 0)
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int print_event(snd_ctl_t *ctl, const char *name)
|
static int print_event(snd_ctl_t *ctl, const char *name)
|
||||||
{
|
{
|
||||||
snd_ctl_event_t *event;
|
snd_ctl_event_t *event;
|
||||||
|
@ -281,8 +304,6 @@ static void clear_dispatcher(int epfd, struct list_head *srcs)
|
||||||
int monitor(const char *name)
|
int monitor(const char *name)
|
||||||
{
|
{
|
||||||
LIST_HEAD(srcs);
|
LIST_HEAD(srcs);
|
||||||
snd_ctl_t *ctls[MAX_CARDS] = {0};
|
|
||||||
int ncards = 0;
|
|
||||||
int epfd;
|
int epfd;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
|
@ -290,29 +311,9 @@ int monitor(const char *name)
|
||||||
if (epfd < 0)
|
if (epfd < 0)
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
if (!name) {
|
err = prepare_source_entry(&srcs, name);
|
||||||
struct snd_card_iterator iter;
|
if (err < 0)
|
||||||
const char *cardname;
|
goto error;
|
||||||
|
|
||||||
snd_card_iterator_init(&iter);
|
|
||||||
while ((cardname = snd_card_iterator_next(&iter))) {
|
|
||||||
err = open_ctl(cardname, &ctls[ncards]);
|
|
||||||
if (err < 0)
|
|
||||||
goto error;
|
|
||||||
err = insert_source_entry(&srcs, ctls[ncards], cardname);
|
|
||||||
if (err < 0)
|
|
||||||
goto error;
|
|
||||||
ncards++;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
err = open_ctl(name, &ctls[0]);
|
|
||||||
if (err < 0)
|
|
||||||
goto error;
|
|
||||||
err = insert_source_entry(&srcs, ctls[ncards], name);
|
|
||||||
if (err < 0)
|
|
||||||
goto error;
|
|
||||||
ncards++;
|
|
||||||
}
|
|
||||||
|
|
||||||
err = prepare_dispatcher(epfd, &srcs);
|
err = prepare_dispatcher(epfd, &srcs);
|
||||||
if (err >= 0)
|
if (err >= 0)
|
||||||
|
|
Loading…
Reference in a new issue