Changeset View
Changeset View
Standalone View
Standalone View
lib/libmixer/mixer.c
Show First 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | mixer_open(const char *name) | ||||
if (name != NULL) { | if (name != NULL) { | ||||
/* `name` does not start with "/dev/mixer". */ | /* `name` does not start with "/dev/mixer". */ | ||||
if (strncmp(name, BASEPATH, strlen(BASEPATH)) != 0) { | if (strncmp(name, BASEPATH, strlen(BASEPATH)) != 0) { | ||||
m->unit = -1; | m->unit = -1; | ||||
} else { | } else { | ||||
/* `name` is "/dev/mixer" so, we'll use the default unit. */ | /* `name` is "/dev/mixer" so, we'll use the default unit. */ | ||||
if (strncmp(name, BASEPATH, strlen(name)) == 0) | if (strncmp(name, BASEPATH, strlen(name)) == 0) | ||||
goto dunit; | goto default_unit; | ||||
m->unit = strtol(name + strlen(BASEPATH), NULL, 10); | m->unit = strtol(name + strlen(BASEPATH), NULL, 10); | ||||
} | } | ||||
(void)strlcpy(m->name, name, sizeof(m->name)); | (void)strlcpy(m->name, name, sizeof(m->name)); | ||||
} else { | } else { | ||||
dunit: | default_unit: | ||||
if ((m->unit = mixer_get_dunit()) < 0) | if ((m->unit = mixer_get_default_unit()) < 0) | ||||
goto fail; | goto fail; | ||||
(void)snprintf(m->name, sizeof(m->name), "/dev/mixer%d", m->unit); | (void)snprintf(m->name, sizeof(m->name), "/dev/mixer%d", m->unit); | ||||
} | } | ||||
if ((m->fd = open(m->name, O_RDWR)) < 0) | if ((m->fd = open(m->name, O_RDWR)) < 0) | ||||
goto fail; | goto fail; | ||||
m->devmask = m->recmask = m->recsrc = 0; | m->devmask = m->recmask = m->recsrc = 0; | ||||
m->f_default = m->unit == mixer_get_dunit(); | m->f_default = m->unit == mixer_get_default_unit(); | ||||
m->mode = mixer_get_mode(m->unit); | m->mode = mixer_get_mode(m->unit); | ||||
/* The unit number _must_ be set before the ioctl. */ | /* The unit number _must_ be set before the ioctl. */ | ||||
m->mi.dev = m->unit; | m->mi.dev = m->unit; | ||||
m->ci.card = m->unit; | m->ci.card = m->unit; | ||||
if (ioctl(m->fd, SNDCTL_MIXERINFO, &m->mi) < 0) { | if (ioctl(m->fd, SNDCTL_MIXERINFO, &m->mi) < 0) { | ||||
memset(&m->mi, 0, sizeof(m->mi)); | memset(&m->mi, 0, sizeof(m->mi)); | ||||
strlcpy(m->mi.name, m->name, sizeof(m->mi.name)); | strlcpy(m->mi.name, m->name, sizeof(m->mi.name)); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 307 Lines • ▼ Show 20 Lines | mixer_mod_recsrc(struct mixer *m, int opt) | ||||
return (0); | return (0); | ||||
} | } | ||||
/* | /* | ||||
* Get default audio card's number. This is used to open the default mixer | * Get default audio card's number. This is used to open the default mixer | ||||
* and set the mixer structure's `f_default` flag. | * and set the mixer structure's `f_default` flag. | ||||
*/ | */ | ||||
int | int | ||||
mixer_get_dunit(void) | mixer_get_default_unit(void) | ||||
{ | { | ||||
size_t size; | size_t size; | ||||
int unit; | int unit; | ||||
size = sizeof(int); | size = sizeof(int); | ||||
if (sysctlbyname("hw.snd.default_unit", &unit, &size, NULL, 0) < 0) | if (sysctlbyname("hw.snd.default_unit", &unit, &size, NULL, 0) < 0) | ||||
return (-1); | return (-1); | ||||
return (unit); | return (unit); | ||||
} | } | ||||
/* | /* | ||||
* Change the default audio card. This is normally _not_ a mixer feature, but | * Change the default audio card. This is normally _not_ a mixer feature, but | ||||
* it's useful to have, so the caller can avoid having to manually use | * it's useful to have, so the caller can avoid having to manually use | ||||
* the sysctl API. | * the sysctl API. | ||||
* | * | ||||
* @param unit the audio card number (e.g pcm0, pcm1, ...). | * @param unit the audio card number (e.g pcm0, pcm1, ...). | ||||
*/ | */ | ||||
int | int | ||||
mixer_set_dunit(struct mixer *m, int unit) | mixer_set_default_unit(struct mixer *m, int unit) | ||||
{ | { | ||||
size_t size; | size_t size; | ||||
size = sizeof(int); | size = sizeof(int); | ||||
if (sysctlbyname("hw.snd.default_unit", NULL, 0, &unit, size) < 0) | if (sysctlbyname("hw.snd.default_unit", NULL, 0, &unit, size) < 0) | ||||
return (-1); | return (-1); | ||||
/* XXX: how will other mixers get updated? */ | /* XXX: how will other mixers get updated? */ | ||||
m->f_default = m->unit == unit; | m->f_default = m->unit == unit; | ||||
▲ Show 20 Lines • Show All 46 Lines • Show Last 20 Lines |