40 lines
1.5 KiB
C
40 lines
1.5 KiB
C
/* sndprobe.c — 探测 /dev/snd/pcmC0D{p,c}* 的 SNDRV_PCM_IOCTL_INFO(id/name/subs),
|
||
* 定位 R3 Pro II 耳机输出到底在哪个 PCM 设备。静态 mipsel,只读不写参数。 */
|
||
#include <stdio.h>
|
||
#include <string.h>
|
||
#include <fcntl.h>
|
||
#include <unistd.h>
|
||
#include <sys/ioctl.h>
|
||
#include <sound/asound.h>
|
||
|
||
int main(void)
|
||
{
|
||
static const char *devs[] = {
|
||
"/dev/snd/pcmC0D0p", "/dev/snd/pcmC0D1p", "/dev/snd/pcmC0D0c", "/dev/snd/pcmC0D1c",
|
||
};
|
||
for (int i = 0; i < 4; i++) {
|
||
int fd = open(devs[i], O_RDWR | O_NONBLOCK);
|
||
if (fd < 0) { printf("%s: open fail\n", devs[i]); continue; }
|
||
struct snd_pcm_info info;
|
||
memset(&info, 0, sizeof info);
|
||
if (ioctl(fd, SNDRV_PCM_IOCTL_INFO, &info) == 0)
|
||
printf("%s: card=%d dev=%d sub=%d id=\"%s\" name=\"%s\" subname=\"%s\" subs=%u/%u\n",
|
||
devs[i], info.card, info.device, info.subdevice,
|
||
info.id, info.name, info.subname, info.subdevices_avail, info.subdevices_count);
|
||
else
|
||
printf("%s: INFO ioctl fail\n", devs[i]);
|
||
close(fd);
|
||
}
|
||
/* 控制设备:看卡名 */
|
||
int cf = open("/dev/snd/controlC0", O_RDONLY);
|
||
if (cf >= 0) {
|
||
struct snd_ctl_card_info ci;
|
||
memset(&ci, 0, sizeof ci);
|
||
if (ioctl(cf, SNDRV_CTL_IOCTL_CARD_INFO, &ci) == 0)
|
||
printf("controlC0: id=\"%s\" driver=\"%s\" name=\"%s\" longname=\"%s\"\n",
|
||
ci.id, ci.driver, ci.name, ci.longname);
|
||
close(cf);
|
||
}
|
||
return 0;
|
||
}
|