Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/sound/pcm/vchan.c
| Show First 20 Lines • Show All 246 Lines • ▼ Show 20 Lines | static kobj_method_t vchan_methods[] = { | ||||
| KOBJMETHOD(channel_setformat, vchan_setformat), | KOBJMETHOD(channel_setformat, vchan_setformat), | ||||
| KOBJMETHOD(channel_setspeed, vchan_setspeed), | KOBJMETHOD(channel_setspeed, vchan_setspeed), | ||||
| KOBJMETHOD(channel_trigger, vchan_trigger), | KOBJMETHOD(channel_trigger, vchan_trigger), | ||||
| KOBJMETHOD(channel_getcaps, vchan_getcaps), | KOBJMETHOD(channel_getcaps, vchan_getcaps), | ||||
| KOBJMETHOD(channel_getmatrix, vchan_getmatrix), | KOBJMETHOD(channel_getmatrix, vchan_getmatrix), | ||||
| KOBJMETHOD_END | KOBJMETHOD_END | ||||
| }; | }; | ||||
| CHANNEL_DECLARE(vchan); | CHANNEL_DECLARE(vchan); | ||||
| static void | |||||
| vchan_getparentchannel(struct snddev_info *d, | |||||
| struct pcm_channel **wrch, struct pcm_channel **rdch) | |||||
| { | |||||
| struct pcm_channel **ch, *wch, *rch, *c; | |||||
| KASSERT(d != NULL, ("%s(): NULL snddev_info", __func__)); | |||||
| PCM_BUSYASSERT(d); | |||||
| PCM_UNLOCKASSERT(d); | |||||
| wch = NULL; | |||||
| rch = NULL; | |||||
| CHN_FOREACH(c, d, channels.pcm) { | |||||
| CHN_LOCK(c); | |||||
| ch = (c->direction == PCMDIR_PLAY) ? &wch : &rch; | |||||
| if (c->flags & CHN_F_VIRTUAL) { | |||||
| /* Sanity check */ | |||||
| if (*ch != NULL && *ch != c->parentchannel) { | |||||
| CHN_UNLOCK(c); | |||||
| *ch = NULL; | |||||
| break; | |||||
| } | |||||
| } else { | |||||
| /* No way!! */ | |||||
| if (*ch != NULL) { | |||||
| CHN_UNLOCK(c); | |||||
| *ch = NULL; | |||||
| break; | |||||
| } | |||||
| *ch = c; | |||||
| } | |||||
| CHN_UNLOCK(c); | |||||
| } | |||||
| if (wrch != NULL) | |||||
| *wrch = wch; | |||||
| if (rdch != NULL) | |||||
| *rdch = rch; | |||||
| } | |||||
| static int | static int | ||||
| sysctl_dev_pcm_vchans(SYSCTL_HANDLER_ARGS) | sysctl_dev_pcm_vchans(SYSCTL_HANDLER_ARGS) | ||||
| { | { | ||||
| struct snddev_info *d; | struct snddev_info *d; | ||||
| int err, enabled, flag; | int err, enabled, flag; | ||||
| d = devclass_get_softc(pcm_devclass, VCHAN_SYSCTL_UNIT(oidp->oid_arg1)); | d = devclass_get_softc(pcm_devclass, VCHAN_SYSCTL_UNIT(oidp->oid_arg1)); | ||||
| if (!PCM_REGISTERED(d) || !(d->flags & SD_F_AUTOVCHAN)) | if (!PCM_REGISTERED(d) || !(d->flags & SD_F_AUTOVCHAN)) | ||||
| ▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | sysctl_dev_pcm_vchanmode(SYSCTL_HANDLER_ARGS) | ||||
| default: | default: | ||||
| PCM_UNLOCK(d); | PCM_UNLOCK(d); | ||||
| return (EINVAL); | return (EINVAL); | ||||
| } | } | ||||
| PCM_ACQUIRE(d); | PCM_ACQUIRE(d); | ||||
| PCM_UNLOCK(d); | PCM_UNLOCK(d); | ||||
| if (direction == PCMDIR_PLAY) | |||||
| vchan_getparentchannel(d, &c, NULL); | |||||
| else | |||||
| vchan_getparentchannel(d, NULL, &c); | |||||
| if (c == NULL) { | |||||
| PCM_RELEASE_QUICK(d); | |||||
| return (EINVAL); | |||||
| } | |||||
| KASSERT(direction == c->direction, ("%s(): invalid direction %d/%d", | |||||
| __func__, direction, c->direction)); | |||||
| if (*vchanmode & CHN_F_VCHAN_PASSTHROUGH) | if (*vchanmode & CHN_F_VCHAN_PASSTHROUGH) | ||||
| strlcpy(dtype, "passthrough", sizeof(dtype)); | strlcpy(dtype, "passthrough", sizeof(dtype)); | ||||
| else if (*vchanmode & CHN_F_VCHAN_ADAPTIVE) | else if (*vchanmode & CHN_F_VCHAN_ADAPTIVE) | ||||
| strlcpy(dtype, "adaptive", sizeof(dtype)); | strlcpy(dtype, "adaptive", sizeof(dtype)); | ||||
| else | else | ||||
| strlcpy(dtype, "fixed", sizeof(dtype)); | strlcpy(dtype, "fixed", sizeof(dtype)); | ||||
| ret = sysctl_handle_string(oidp, dtype, sizeof(dtype), req); | ret = sysctl_handle_string(oidp, dtype, sizeof(dtype), req); | ||||
| if (ret == 0 && req->newptr != NULL) { | if (ret != 0 || req->newptr == NULL) { | ||||
| if (strcasecmp(dtype, "passthrough") == 0 || | PCM_RELEASE_QUICK(d); | ||||
| strcmp(dtype, "1") == 0) | return (ret); | ||||
| } | |||||
| if (strcasecmp(dtype, "passthrough") == 0 || strcmp(dtype, "1") == 0) | |||||
| dflags = CHN_F_VCHAN_PASSTHROUGH; | dflags = CHN_F_VCHAN_PASSTHROUGH; | ||||
| else if (strcasecmp(dtype, "adaptive") == 0 || | else if (strcasecmp(dtype, "adaptive") == 0 || strcmp(dtype, "2") == 0) | ||||
| strcmp(dtype, "2") == 0) | |||||
| dflags = CHN_F_VCHAN_ADAPTIVE; | dflags = CHN_F_VCHAN_ADAPTIVE; | ||||
| else if (strcasecmp(dtype, "fixed") == 0 || | else if (strcasecmp(dtype, "fixed") == 0 || strcmp(dtype, "0") == 0) | ||||
| strcmp(dtype, "0") == 0) | |||||
| dflags = 0; | dflags = 0; | ||||
| else { | else { | ||||
| PCM_RELEASE_QUICK(d); | PCM_RELEASE_QUICK(d); | ||||
| return (EINVAL); | return (EINVAL); | ||||
| } | } | ||||
| CHN_FOREACH(c, d, channels.pcm.primary) { | |||||
| CHN_LOCK(c); | CHN_LOCK(c); | ||||
| if (dflags == (c->flags & CHN_F_VCHAN_DYNAMIC) || | if (c->direction != direction || | ||||
| dflags == (c->flags & CHN_F_VCHAN_DYNAMIC) || | |||||
| (c->flags & CHN_F_PASSTHROUGH)) { | (c->flags & CHN_F_PASSTHROUGH)) { | ||||
| CHN_UNLOCK(c); | CHN_UNLOCK(c); | ||||
| PCM_RELEASE_QUICK(d); | continue; | ||||
| return (0); | |||||
| } | } | ||||
| c->flags &= ~CHN_F_VCHAN_DYNAMIC; | c->flags &= ~CHN_F_VCHAN_DYNAMIC; | ||||
| c->flags |= dflags; | c->flags |= dflags; | ||||
| CHN_UNLOCK(c); | CHN_UNLOCK(c); | ||||
| *vchanmode = dflags; | *vchanmode = dflags; | ||||
| } | } | ||||
| PCM_RELEASE_QUICK(d); | PCM_RELEASE_QUICK(d); | ||||
| ▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | sysctl_dev_pcm_vchanrate(SYSCTL_HANDLER_ARGS) | ||||
| default: | default: | ||||
| PCM_UNLOCK(d); | PCM_UNLOCK(d); | ||||
| return (EINVAL); | return (EINVAL); | ||||
| } | } | ||||
| PCM_ACQUIRE(d); | PCM_ACQUIRE(d); | ||||
| PCM_UNLOCK(d); | PCM_UNLOCK(d); | ||||
| if (direction == PCMDIR_PLAY) | |||||
| vchan_getparentchannel(d, &c, NULL); | |||||
| else | |||||
| vchan_getparentchannel(d, NULL, &c); | |||||
| if (c == NULL) { | |||||
| PCM_RELEASE_QUICK(d); | |||||
| return (EINVAL); | |||||
| } | |||||
| KASSERT(direction == c->direction, ("%s(): invalid direction %d/%d", | |||||
| __func__, direction, c->direction)); | |||||
| newspd = *vchanrate; | newspd = *vchanrate; | ||||
| ret = sysctl_handle_int(oidp, &newspd, 0, req); | ret = sysctl_handle_int(oidp, &newspd, 0, req); | ||||
| if (ret != 0 || req->newptr == NULL) { | if (ret != 0 || req->newptr == NULL) { | ||||
| PCM_RELEASE_QUICK(d); | PCM_RELEASE_QUICK(d); | ||||
| return (ret); | return (ret); | ||||
| } | } | ||||
| if (newspd < feeder_rate_min || newspd > feeder_rate_max) { | if (newspd < feeder_rate_min || newspd > feeder_rate_max) { | ||||
| PCM_RELEASE_QUICK(d); | PCM_RELEASE_QUICK(d); | ||||
| return (EINVAL); | return (EINVAL); | ||||
| } | } | ||||
| CHN_FOREACH(c, d, channels.pcm.primary) { | |||||
| CHN_LOCK(c); | CHN_LOCK(c); | ||||
| if (c->direction != direction) { | |||||
| CHN_UNLOCK(c); | |||||
| continue; | |||||
| } | |||||
| if (newspd != c->speed && VCHAN_ACCESSIBLE(c)) { | if (newspd != c->speed && VCHAN_ACCESSIBLE(c)) { | ||||
| if (CHN_STARTED(c)) { | if (CHN_STARTED(c)) { | ||||
| chn_abort(c); | chn_abort(c); | ||||
| restart = 1; | restart = 1; | ||||
| } else | } else | ||||
| restart = 0; | restart = 0; | ||||
| if (feeder_rate_round) { | if (feeder_rate_round) { | ||||
| caps = chn_getcaps(c); | caps = chn_getcaps(c); | ||||
| RANGE(newspd, caps->minspeed, caps->maxspeed); | RANGE(newspd, caps->minspeed, caps->maxspeed); | ||||
| newspd = CHANNEL_SETSPEED(c->methods, | newspd = CHANNEL_SETSPEED(c->methods, | ||||
| c->devinfo, newspd); | c->devinfo, newspd); | ||||
| } | } | ||||
| ret = chn_reset(c, c->format, newspd); | ret = chn_reset(c, c->format, newspd); | ||||
| if (ret == 0) { | if (ret == 0) { | ||||
| if (restart != 0) { | if (restart != 0) { | ||||
| CHN_FOREACH(ch, c, children.busy) { | CHN_FOREACH(ch, c, children.busy) { | ||||
| CHN_LOCK(ch); | CHN_LOCK(ch); | ||||
| if (VCHAN_SYNC_REQUIRED(ch)) | if (VCHAN_SYNC_REQUIRED(ch)) | ||||
| vchan_sync(ch); | vchan_sync(ch); | ||||
| CHN_UNLOCK(ch); | CHN_UNLOCK(ch); | ||||
| } | } | ||||
| c->flags |= CHN_F_DIRTY; | c->flags |= CHN_F_DIRTY; | ||||
| ret = chn_start(c, 1); | ret = chn_start(c, 1); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| *vchanrate = c->speed; | *vchanrate = c->speed; | ||||
christos: I am aware that in case there are >2 primary channels per-directions, then this will always be… | |||||
Not Done Inline ActionsThat's fine, I don't see any other strategy that would make more sense. dev_submerge.ch: That's fine, I don't see any other strategy that would make more sense. | |||||
| CHN_UNLOCK(c); | CHN_UNLOCK(c); | ||||
| } | |||||
| PCM_RELEASE_QUICK(d); | PCM_RELEASE_QUICK(d); | ||||
| return (ret); | return (ret); | ||||
| } | } | ||||
| static int | static int | ||||
| sysctl_dev_pcm_vchanformat(SYSCTL_HANDLER_ARGS) | sysctl_dev_pcm_vchanformat(SYSCTL_HANDLER_ARGS) | ||||
| Show All 30 Lines | case VCHAN_REC: | ||||
| break; | break; | ||||
| default: | default: | ||||
| PCM_UNLOCK(d); | PCM_UNLOCK(d); | ||||
| return (EINVAL); | return (EINVAL); | ||||
| } | } | ||||
| PCM_ACQUIRE(d); | PCM_ACQUIRE(d); | ||||
| PCM_UNLOCK(d); | PCM_UNLOCK(d); | ||||
| if (direction == PCMDIR_PLAY) | |||||
| vchan_getparentchannel(d, &c, NULL); | |||||
| else | |||||
| vchan_getparentchannel(d, NULL, &c); | |||||
| if (c == NULL) { | |||||
| PCM_RELEASE_QUICK(d); | |||||
| return (EINVAL); | |||||
| } | |||||
| KASSERT(direction == c->direction, ("%s(): invalid direction %d/%d", | |||||
| __func__, direction, c->direction)); | |||||
| bzero(fmtstr, sizeof(fmtstr)); | bzero(fmtstr, sizeof(fmtstr)); | ||||
| if (snd_afmt2str(*vchanformat, fmtstr, sizeof(fmtstr)) != *vchanformat) | if (snd_afmt2str(*vchanformat, fmtstr, sizeof(fmtstr)) != *vchanformat) | ||||
| strlcpy(fmtstr, "<ERROR>", sizeof(fmtstr)); | strlcpy(fmtstr, "<ERROR>", sizeof(fmtstr)); | ||||
| ret = sysctl_handle_string(oidp, fmtstr, sizeof(fmtstr), req); | ret = sysctl_handle_string(oidp, fmtstr, sizeof(fmtstr), req); | ||||
| if (ret != 0 || req->newptr == NULL) { | if (ret != 0 || req->newptr == NULL) { | ||||
| PCM_RELEASE_QUICK(d); | PCM_RELEASE_QUICK(d); | ||||
| return (ret); | return (ret); | ||||
| } | } | ||||
| newfmt = snd_str2afmt(fmtstr); | newfmt = snd_str2afmt(fmtstr); | ||||
| if (newfmt == 0 || !(newfmt & AFMT_VCHAN)) { | if (newfmt == 0 || !(newfmt & AFMT_VCHAN)) { | ||||
| PCM_RELEASE_QUICK(d); | PCM_RELEASE_QUICK(d); | ||||
| return (EINVAL); | return (EINVAL); | ||||
| } | } | ||||
| CHN_FOREACH(c, d, channels.pcm.primary) { | |||||
| CHN_LOCK(c); | CHN_LOCK(c); | ||||
| if (c->direction != direction) { | |||||
| CHN_UNLOCK(c); | |||||
| continue; | |||||
| } | |||||
Done Inline ActionsWrong order, the if block should come after the CHN_LOCK(c);, this panics. dev_submerge.ch: Wrong order, the if block should come after the `CHN_LOCK(c);`, this panics. | |||||
Done Inline ActionsSorry for this obvious mistake... I was travelling back home for hours and was kind of tired. Thanks for pointing this and the others out. :-) christos: Sorry for this obvious mistake... I was travelling back home for hours and was kind of tired. | |||||
| if (newfmt != c->format && VCHAN_ACCESSIBLE(c)) { | if (newfmt != c->format && VCHAN_ACCESSIBLE(c)) { | ||||
| if (CHN_STARTED(c)) { | if (CHN_STARTED(c)) { | ||||
| chn_abort(c); | chn_abort(c); | ||||
| restart = 1; | restart = 1; | ||||
| } else | } else | ||||
| restart = 0; | restart = 0; | ||||
| ret = chn_reset(c, newfmt, c->speed); | ret = chn_reset(c, newfmt, c->speed); | ||||
| if (ret == 0) { | if (ret == 0) { | ||||
| if (restart != 0) { | if (restart != 0) { | ||||
| CHN_FOREACH(ch, c, children.busy) { | CHN_FOREACH(ch, c, children.busy) { | ||||
| CHN_LOCK(ch); | CHN_LOCK(ch); | ||||
| if (VCHAN_SYNC_REQUIRED(ch)) | if (VCHAN_SYNC_REQUIRED(ch)) | ||||
| vchan_sync(ch); | vchan_sync(ch); | ||||
| CHN_UNLOCK(ch); | CHN_UNLOCK(ch); | ||||
| } | } | ||||
| c->flags |= CHN_F_DIRTY; | c->flags |= CHN_F_DIRTY; | ||||
| ret = chn_start(c, 1); | ret = chn_start(c, 1); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| *vchanformat = c->format; | *vchanformat = c->format; | ||||
| CHN_UNLOCK(c); | CHN_UNLOCK(c); | ||||
| } | |||||
| PCM_RELEASE_QUICK(d); | PCM_RELEASE_QUICK(d); | ||||
| return (ret); | return (ret); | ||||
| } | } | ||||
| /* virtual channel interface */ | /* virtual channel interface */ | ||||
| ▲ Show 20 Lines • Show All 320 Lines • Show Last 20 Lines | |||||
I am aware that in case there are >2 primary channels per-directions, then this will always be set to whatever the last primary channel's speed (and similarly for the format below) is. Not sure if we should care too much about this though.