more simple mixer - basic abstraction - work

- midlayer cleanups and simplification
- probably broke the "none" abstraction code somehow (not intensively tested
  midlayer changes)
- trying to implement ac97 module
  - far from finished
  - common code should be moved to alsa-lib as core for other modules
  - perhaps simple_abst.c can be based on this common code, too
This commit is contained in:
Jaroslav Kysela 2005-06-16 11:59:26 +00:00
parent 3656a66397
commit ce67d5389b
8 changed files with 856 additions and 298 deletions

View file

@ -190,24 +190,42 @@ static int hctl_event_handler(snd_hctl_t *hctl, unsigned int mask,
/**
* \brief Attach an HCTL to an opened mixer
* \brief Attach an HCTL specified with the CTL device name to an opened mixer
* \param mixer Mixer handle
* \param name HCTL name (see #snd_hctl_open)
* \return 0 on success otherwise a negative error code
*/
int snd_mixer_attach(snd_mixer_t *mixer, const char *name)
{
snd_mixer_slave_t *slave;
snd_hctl_t *hctl;
int err;
err = snd_hctl_open(&hctl, name, 0);
if (err < 0)
return err;
err = snd_mixer_attach_hctl(mixer, hctl);
if (err < 0) {
snd_hctl_close(hctl);
return err;
}
return 0;
}
/**
* \brief Attach an HCTL to an opened mixer
* \param mixer Mixer handle
* \param name HCTL name (see #snd_hctl_open)
* \return 0 on success otherwise a negative error code
*/
int snd_mixer_attach_hctl(snd_mixer_t *mixer, snd_hctl_t *hctl)
{
snd_mixer_slave_t *slave;
int err;
assert(hctl);
slave = calloc(1, sizeof(*slave));
if (slave == NULL)
return -ENOMEM;
err = snd_hctl_open(&hctl, name, 0);
if (err < 0) {
free(slave);
return err;
}
err = snd_hctl_nonblock(hctl, 1);
if (err < 0) {
snd_hctl_close(hctl);
@ -243,6 +261,29 @@ int snd_mixer_detach(snd_mixer_t *mixer, const char *name)
return -ENOENT;
}
/**
* \brief Detach a previously attached HCTL to an opened mixer freeing all related resources
* \param mixer Mixer handle
* \param hctl HCTL previously attached
* \return 0 on success otherwise a negative error code
*
* Note: The hctl handle is not closed!
*/
int snd_mixer_detach_hctl(snd_mixer_t *mixer, snd_hctl_t *hctl)
{
struct list_head *pos;
list_for_each(pos, &mixer->slaves) {
snd_mixer_slave_t *s;
s = list_entry(pos, snd_mixer_slave_t, list);
if (hctl == s->hctl) {
list_del(pos);
free(s);
return 0;
}
}
return -ENOENT;
}
/**
* \brief Obtain a HCTL pointer associated to given name
* \param mixer Mixer handle