sound: Retire snd_mixer->enuminfo
Instead of caching this when mix_setrecdevs() is called (which many drivers never call), calculate it when we need it. After all, it is quite rare that this structure is used by applications. Sponsored by: The FreeBSD Foundation MFC after: 1 week Pull Request: https://ron-dev.freebsd.org/FreeBSD/src/pulls/18
This commit is contained in:
+23
-55
@@ -56,7 +56,6 @@ struct snd_mixer {
|
||||
u_int8_t realdev[32];
|
||||
char name[MIXER_NAMELEN];
|
||||
struct mtx lock;
|
||||
oss_mixer_enuminfo enuminfo;
|
||||
int modify_counter;
|
||||
};
|
||||
|
||||
@@ -493,64 +492,12 @@ mix_setdevs(struct snd_mixer *m, u_int32_t v)
|
||||
* recording devices. This function records that value in a structure
|
||||
* used by the rest of the mixer code.
|
||||
*
|
||||
* This function also populates a structure used by the SNDCTL_DSP_*RECSRC*
|
||||
* family of ioctls that are part of OSSV4. All recording device labels
|
||||
* are concatenated in ascending order corresponding to their routing
|
||||
* numbers. (Ex: a system might have 0 => 'vol', 1 => 'cd', 2 => 'line',
|
||||
* etc.) For now, these labels are just the standard recording device
|
||||
* names (cd, line1, etc.), but will eventually be fully dynamic and user
|
||||
* controlled.
|
||||
*
|
||||
* @param m mixer device context container thing
|
||||
* @param v mask of recording devices
|
||||
*/
|
||||
void
|
||||
mix_setrecdevs(struct snd_mixer *m, u_int32_t v)
|
||||
{
|
||||
oss_mixer_enuminfo *ei;
|
||||
char *loc;
|
||||
int i, nvalues, nwrote, nleft, ncopied;
|
||||
|
||||
ei = &m->enuminfo;
|
||||
|
||||
nvalues = 0;
|
||||
nwrote = 0;
|
||||
nleft = sizeof(ei->strings);
|
||||
loc = ei->strings;
|
||||
|
||||
for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
|
||||
if ((1 << i) & v) {
|
||||
ei->strindex[nvalues] = nwrote;
|
||||
ncopied = strlcpy(loc, snd_mixernames[i], nleft) + 1;
|
||||
/* strlcpy retval doesn't include terminator */
|
||||
|
||||
nwrote += ncopied;
|
||||
nleft -= ncopied;
|
||||
nvalues++;
|
||||
|
||||
/*
|
||||
* XXX I don't think this should ever be possible.
|
||||
* Even with a move to dynamic device/channel names,
|
||||
* each label is limited to ~16 characters, so that'd
|
||||
* take a LOT to fill this buffer.
|
||||
*/
|
||||
if ((nleft <= 0) || (nvalues >= OSS_ENUM_MAXVALUE)) {
|
||||
device_printf(m->dev,
|
||||
"mix_setrecdevs: Not enough room to store device names--please file a bug report.\n");
|
||||
device_printf(m->dev,
|
||||
"mix_setrecdevs: Please include details about your sound hardware, OS version, etc.\n");
|
||||
break;
|
||||
}
|
||||
|
||||
loc = &ei->strings[nwrote];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* NB: The SNDCTL_DSP_GET_RECSRC_NAMES ioctl ignores the dev
|
||||
* and ctrl fields.
|
||||
*/
|
||||
ei->nvalues = nvalues;
|
||||
m->recdevs = v;
|
||||
}
|
||||
|
||||
@@ -1104,10 +1051,31 @@ mixer_ioctl_cmd(struct cdev *i_dev, u_long cmd, caddr_t arg, int mode,
|
||||
|
||||
mtx_lock(&m->lock);
|
||||
switch (cmd) {
|
||||
case SNDCTL_DSP_GET_RECSRC_NAMES:
|
||||
bcopy((void *)&m->enuminfo, arg, sizeof(oss_mixer_enuminfo));
|
||||
case SNDCTL_DSP_GET_RECSRC_NAMES: {
|
||||
oss_mixer_enuminfo *ei = (oss_mixer_enuminfo *)arg;
|
||||
char *loc;
|
||||
int i, nvalues, nwrote, nleft, ncopied;
|
||||
|
||||
nvalues = 0;
|
||||
nwrote = 0;
|
||||
nleft = sizeof(ei->strings);
|
||||
loc = ei->strings;
|
||||
|
||||
for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
|
||||
if (!((1 << i) & m->recdevs))
|
||||
continue;
|
||||
ei->strindex[nvalues] = nwrote;
|
||||
ncopied = strlcpy(loc, snd_mixernames[i], nleft) + 1;
|
||||
nwrote += ncopied;
|
||||
nleft -= ncopied;
|
||||
nvalues++;
|
||||
loc = &ei->strings[nwrote];
|
||||
}
|
||||
ei->nvalues = nvalues;
|
||||
|
||||
ret = 0;
|
||||
goto done;
|
||||
}
|
||||
case SNDCTL_DSP_GET_RECSRC:
|
||||
ret = mixer_get_recroute(m, arg_i);
|
||||
goto done;
|
||||
|
||||
Reference in New Issue
Block a user