我想将相同的功能从 oss 混合器移植到 alsa,但我现在不知道如何检查设备通道是否具有捕获掩码。开源代码:
这些函数处理混音器设备
static int mixer_fd = -1, mixer_src = -1;
int mixer_init(char *mixer_device, char *mixer_source)
{
int i;
mixer_src = -1;
for (i=0;i<SOUND_MIXER_NRDEVICES;i++)
if (strcmp(mixer_source, devices[i]) == 0)
mixer_src = i;
mixer_fd = open(mixer_device, O_RDWR);
if (mixer_src < 0)
return -1;
if (mixer_fd < 0)
return 0;
return 1;
}
char** mixer_get_rec_devices(void)
{
int i, o, devmask, res;
char** result;
if ((ioctl(mixer_fd, SOUND_MIXER_READ_RECMASK, &devmask)) == -1)
return NULL;
else
{
result = malloc(sizeof(char*)*SOUND_MIXER_NRDEVICES);
o = 0;
for (i=0;i<SOUND_MIXER_NRDEVICES;i++)
{
res = (devmask >> i)%2;
if (res)
{
result[o] = malloc(strlen(devices[i])+1);
sprintf(result[o], "%s", devices[i]);
o++;
}
result[o] = NULL;
}
}
return result;
}
int mixer_set_rec_device(void)
{
int devmask, recmask;
if (mixer_fd <= 0)
return 0;
if (mixer_src < 0)
return 0;
if ((ioctl(mixer_fd, SOUND_MIXER_READ_RECMASK, &devmask)) == -1)
return 0;
recmask = 1 << mixer_src;
if (!(recmask & devmask))
return 0;
if ((ioctl(mixer_fd, SOUND_MIXER_WRITE_RECSRC, &recmask)) == -1)
return 0;
return 1;
}
我需要帮助将此代码移植到 ALSA 混音器。
函数“mixer_set_rec_device()”用于检查如果用户激活录制,通道混音器是否可以录制,其中 settings.mixer 是用户选择的通道。
if (!mixer_set_rec_device()) {
fprintf(stderr, "Could not set \"%s\" as recording Source", settings.mixer);
return -1;
}