diff --git a/sys/dev/sound/pcm/channel.h b/sys/dev/sound/pcm/channel.h --- a/sys/dev/sound/pcm/channel.h +++ b/sys/dev/sound/pcm/channel.h @@ -260,6 +260,7 @@ int chn_flush(struct pcm_channel *c); int chn_poll(struct pcm_channel *c, int ev, struct thread *td); +char *chn_mkname(char *buf, size_t len, struct pcm_channel *c); struct pcm_channel *chn_init(struct snddev_info *d, struct pcm_channel *parent, kobj_class_t cls, int dir, void *devinfo); void chn_kill(struct pcm_channel *c); diff --git a/sys/dev/sound/pcm/channel.c b/sys/dev/sound/pcm/channel.c --- a/sys/dev/sound/pcm/channel.c +++ b/sys/dev/sound/pcm/channel.c @@ -1161,13 +1161,13 @@ chn_getunr(struct snddev_info *d, int type) { switch (type) { - case SND_DEV_DSPHW_PLAY: + case PCMDIR_PLAY: return (d->p_unr); - case SND_DEV_DSPHW_VPLAY: + case PCMDIR_PLAY_VIRTUAL: return (d->vp_unr); - case SND_DEV_DSPHW_REC: + case PCMDIR_REC: return (d->r_unr); - case SND_DEV_DSPHW_VREC: + case PCMDIR_REC_VIRTUAL: return (d->vr_unr); default: __assert_unreachable(); @@ -1175,6 +1175,35 @@ } +static const struct { + int type; + char *name; +} chn_names[] = { + { PCMDIR_PLAY, ".play." }, + { PCMDIR_PLAY_VIRTUAL, ".virtual_play." }, + { PCMDIR_REC, ".record." }, + { PCMDIR_REC_VIRTUAL, ".virtual_record." }, +}; + +char * +chn_mkname(char *buf, size_t len, struct pcm_channel *c) +{ + size_t i; + + KASSERT(buf != NULL && len != 0, + ("%s(): bogus buf=%p len=%lu", __func__, buf, len)); + + for (i = 0; i < nitems(chn_names); i++) { + if (c->type != chn_names[i].type) + continue; + snprintf(buf, len, "dsp%d%s%d", + device_get_unit(c->dev), chn_names[i].name, c->unit); + return (buf); + } + + return (NULL); +} + struct pcm_channel * chn_init(struct snddev_info *d, struct pcm_channel *parent, kobj_class_t cls, int dir, void *devinfo) @@ -1183,27 +1212,19 @@ struct feeder_class *fc; struct snd_dbuf *b, *bs; char buf[CHN_NAMELEN]; - int i, direction, type; + int i, direction; PCM_BUSYASSERT(d); PCM_LOCKASSERT(d); switch (dir) { case PCMDIR_PLAY: - direction = PCMDIR_PLAY; - type = SND_DEV_DSPHW_PLAY; - break; case PCMDIR_PLAY_VIRTUAL: direction = PCMDIR_PLAY; - type = SND_DEV_DSPHW_VPLAY; break; case PCMDIR_REC: - direction = PCMDIR_REC; - type = SND_DEV_DSPHW_REC; - break; case PCMDIR_REC_VIRTUAL: direction = PCMDIR_REC; - type = SND_DEV_DSPHW_VREC; break; default: device_printf(d->dev, @@ -1222,7 +1243,7 @@ CHN_INIT(c, children); CHN_INIT(c, children.busy); c->direction = direction; - c->type = type; + c->type = dir; c->unit = alloc_unr(chn_getunr(d, c->type)); c->format = SND_FORMAT(AFMT_U8, 1, 0); c->speed = DSP_DEFAULT_SPEED; @@ -1234,8 +1255,7 @@ c->parentchannel = parent; c->dev = d->dev; c->trigger = PCMTRIG_STOP; - - strlcpy(c->name, dsp_unit2name(buf, sizeof(buf), c), sizeof(c->name)); + strlcpy(c->name, chn_mkname(buf, sizeof(buf), c), sizeof(c->name)); c->matrix = *feeder_matrix_id_map(SND_CHN_MATRIX_1_0); c->matrix.id = SND_CHN_MATRIX_PCMCHANNEL; @@ -1303,16 +1323,16 @@ CHN_INSERT_SORT_ASCEND(d, c, channels.pcm); switch (c->type) { - case SND_DEV_DSPHW_PLAY: + case PCMDIR_PLAY: d->playcount++; break; - case SND_DEV_DSPHW_VPLAY: + case PCMDIR_PLAY_VIRTUAL: d->pvchancount++; break; - case SND_DEV_DSPHW_REC: + case PCMDIR_REC: d->reccount++; break; - case SND_DEV_DSPHW_VREC: + case PCMDIR_REC_VIRTUAL: d->rvchancount++; break; default: @@ -1354,16 +1374,16 @@ CHN_REMOVE(d, c, channels.pcm); switch (c->type) { - case SND_DEV_DSPHW_PLAY: + case PCMDIR_PLAY: d->playcount--; break; - case SND_DEV_DSPHW_VPLAY: + case PCMDIR_PLAY_VIRTUAL: d->pvchancount--; break; - case SND_DEV_DSPHW_REC: + case PCMDIR_REC: d->reccount--; break; - case SND_DEV_DSPHW_VREC: + case PCMDIR_REC_VIRTUAL: d->rvchancount--; break; default: diff --git a/sys/dev/sound/pcm/dsp.h b/sys/dev/sound/pcm/dsp.h --- a/sys/dev/sound/pcm/dsp.h +++ b/sys/dev/sound/pcm/dsp.h @@ -35,7 +35,6 @@ int dsp_make_dev(device_t); void dsp_destroy_dev(device_t); -char *dsp_unit2name(char *, size_t, struct pcm_channel *); int dsp_oss_audioinfo(struct cdev *, oss_audioinfo *, bool); int dsp_oss_engineinfo(struct cdev *, oss_audioinfo *); diff --git a/sys/dev/sound/pcm/dsp.c b/sys/dev/sound/pcm/dsp.c --- a/sys/dev/sound/pcm/dsp.c +++ b/sys/dev/sound/pcm/dsp.c @@ -164,25 +164,6 @@ #define DSP_F_READ(x) ((x) & FREAD) #define DSP_F_WRITE(x) ((x) & FWRITE) -static const struct { - int type; - char *name; - char *sep; - char *alias; -} dsp_cdevs[] = { - { SND_DEV_DSP, "dsp", ".", NULL }, - { SND_DEV_DSPHW_PLAY, "dsp", ".play.", NULL }, - { SND_DEV_DSPHW_VPLAY, "dsp", ".virtual_play.", NULL }, - { SND_DEV_DSPHW_REC, "dsp", ".record.", NULL }, - { SND_DEV_DSPHW_VREC, "dsp", ".virtual_record.", NULL }, - /* Low priority, OSSv4 aliases. */ - { SND_DEV_DSP, "dsp_ac3", ".", "dsp" }, - { SND_DEV_DSP, "dsp_mmap", ".", "dsp" }, - { SND_DEV_DSP, "dsp_multich", ".", "dsp" }, - { SND_DEV_DSP, "dsp_spdifout", ".", "dsp" }, - { SND_DEV_DSP, "dsp_spdifin", ".", "dsp" }, -}; - static void dsp_close(void *data) { @@ -1941,20 +1922,26 @@ return (0); } +static const char *dsp_aliases[] = { + "dsp_ac3", + "dsp_mmap", + "dsp_multich", + "dsp_spdifout", + "dsp_spdifin", +}; + static void dsp_clone(void *arg, struct ucred *cred, char *name, int namelen, struct cdev **dev) { struct snddev_info *d; size_t i; - if (*dev != NULL) return; if (strcmp(name, "dsp") == 0 && dsp_basename_clone) goto found; - for (i = 0; i < nitems(dsp_cdevs); i++) { - if (dsp_cdevs[i].alias != NULL && - strcmp(name, dsp_cdevs[i].name) == 0) + for (i = 0; i < nitems(dsp_aliases); i++) { + if (strcmp(name, dsp_aliases[i]) == 0) goto found; } return; @@ -1994,26 +1981,6 @@ SYSINIT(dsp_sysinit, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, dsp_sysinit, NULL); SYSUNINIT(dsp_sysuninit, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, dsp_sysuninit, NULL); -char * -dsp_unit2name(char *buf, size_t len, struct pcm_channel *ch) -{ - size_t i; - - KASSERT(buf != NULL && len != 0, - ("bogus buf=%p len=%ju", buf, (uintmax_t)len)); - - for (i = 0; i < nitems(dsp_cdevs); i++) { - if (ch->type != dsp_cdevs[i].type || dsp_cdevs[i].alias != NULL) - continue; - snprintf(buf, len, "%s%d%s%d", - dsp_cdevs[i].name, device_get_unit(ch->dev), - dsp_cdevs[i].sep, ch->unit); - return (buf); - } - - return (NULL); -} - static void dsp_oss_audioinfo_unavail(oss_audioinfo *ai, int unit) { @@ -2270,11 +2237,11 @@ if (ai->dev == -1) { if (devfs_foreach_cdevpriv(i_dev, dsp_oss_engineinfo_cb, ch) != 0) { - devname = dsp_unit2name(buf, + devname = chn_mkname(buf, sizeof(buf), ch); } } else if (ai->dev == nchan) - devname = dsp_unit2name(buf, sizeof(buf), ch); + devname = chn_mkname(buf, sizeof(buf), ch); if (devname != NULL) break; CHN_UNLOCK(ch); diff --git a/sys/dev/sound/pcm/sound.h b/sys/dev/sound/pcm/sound.h --- a/sys/dev/sound/pcm/sound.h +++ b/sys/dev/sound/pcm/sound.h @@ -225,10 +225,6 @@ SND_DEV_MIDIN, /* Raw midi access */ SND_DEV_DSP, /* Digitized voice /dev/dsp */ SND_DEV_STATUS, /* /dev/sndstat */ - SND_DEV_DSPHW_PLAY, /* specific playback channel */ - SND_DEV_DSPHW_VPLAY, /* specific virtual playback channel */ - SND_DEV_DSPHW_REC, /* specific record channel */ - SND_DEV_DSPHW_VREC, /* specific virtual record channel */ }; #define DSP_DEFAULT_SPEED 8000 diff --git a/sys/dev/sound/pcm/vchan.c b/sys/dev/sound/pcm/vchan.c --- a/sys/dev/sound/pcm/vchan.c +++ b/sys/dev/sound/pcm/vchan.c @@ -889,7 +889,7 @@ if (snd_passthrough_verbose != 0) { char *devname, buf[CHN_NAMELEN]; - devname = dsp_unit2name(buf, sizeof(buf), c); + devname = chn_mkname(buf, sizeof(buf), c); device_printf(c->dev, "%s(%s/%s) %s() -> re-sync err=%d\n", __func__, (devname != NULL) ? devname : "dspX", c->comm,