static const char* search_device(void) { int card, err; snd_hwdep_info_t* info; snd_hwdep_info_alloca(&info); card = -1; while (snd_card_next(&card) >= 0 && card >= 0) { char ctl_name[20]; snd_ctl_t* ctl; int device; sprintf(ctl_name, "hw:CARD=%d", card); err = snd_ctl_open(&ctl, ctl_name, SND_CTL_NONBLOCK); if (err < 0) continue; device = -1; while (snd_ctl_hwdep_next_device(ctl, &device) >= 0 && device >= 0) { snd_hwdep_info_set_device(info, device); err = snd_ctl_hwdep_info(ctl, info); if (err >= 0 && snd_hwdep_info_get_iface(info) == SND_HWDEP_IFACE_SB_RC) { static char name[36]; sprintf(name, "hw:CARD=%d,DEV=%d", card, device); snd_ctl_close(ctl); return name; } } snd_ctl_close(ctl); } return NULL; }
/* * check the name id of the given hwdep handle */ static int check_hwinfo(snd_hwdep_t *hw, const char *id) { snd_hwdep_info_t *info; int err; snd_hwdep_info_alloca(&info); if ((err = snd_hwdep_info(hw, info)) < 0) return err; if (strcmp(snd_hwdep_info_get_id(info), id)) return -ENODEV; return 0; /* ok */ }
static int init(void) { const char* device; snd_hwdep_info_t* info; struct pollfd pollfd; int err; device = drv.device; if (!device || !*device) { device = search_device(); if (!device) { logprintf(LIRC_ERROR, "device not found"); return 0; } } err = snd_hwdep_open(&hwdep, device, SND_HWDEP_OPEN_READ); if (err < 0) { logprintf(LIRC_ERROR, "cannot open %s: %s", device, snd_strerror(err)); return 0; } snd_hwdep_info_alloca(&info); err = snd_hwdep_info(hwdep, info); if (err < 0) { snd_hwdep_close(hwdep); logprintf(LIRC_ERROR, "cannot get hwdep info: %s", snd_strerror(err)); return 0; } if (snd_hwdep_info_get_iface(info) != SND_HWDEP_IFACE_SB_RC) { snd_hwdep_close(hwdep); logprintf(LIRC_ERROR, "%s is not a Sound Blaster remote control device", device); return 0; } err = snd_hwdep_poll_descriptors(hwdep, &pollfd, 1); if (err < 0) { snd_hwdep_close(hwdep); logprintf(LIRC_ERROR, "cannot get file descriptor: %s", snd_strerror(err)); return 0; } if (err != 1) { snd_hwdep_close(hwdep); logprintf(LIRC_ERROR, "invalid number of file descriptors (%d): %s", err, snd_strerror(err)); return 0; } drv.fd = pollfd.fd; return 1; }
static int find_hwdep_device(int *cardP, int *devP) { snd_ctl_t *ctl_handle; snd_ctl_card_info_t *card_info; snd_hwdep_info_t *hwdep_info; int card; int dev; int err; char card_id[32]; ctl_handle = NULL; snd_ctl_card_info_alloca(&card_info); snd_hwdep_info_alloca(&hwdep_info); for (card = 0; card < 7; card++) { *cardP = card; if (ctl_handle) { snd_ctl_close(ctl_handle); ctl_handle = NULL; } // Get control handle for selected card sprintf(card_id, "hw:%i", card); if ((err = snd_ctl_open(&ctl_handle, card_id, 0)) < 0) { fprintf(stderr, "control open (%s): %s", card_id, snd_strerror(err)); return -1; } // Read control hardware info from card if ((err = snd_ctl_card_info(ctl_handle, card_info)) < 0) { fprintf(stderr, "control hardware info (%s): %s", card_id, snd_strerror(err)); continue; } //if (strcmp(snd_ctl_card_info_get_driver(card_info),"BT SCO (d)")) // continue; dev = -1; err = 1; while (1) { int if_type; if (snd_ctl_hwdep_next_device(ctl_handle, &dev) < 0) fprintf(stderr, "hwdep next device (%s): %s", card_id, snd_strerror(err)); if (dev < 0) break; snd_hwdep_info_set_device(hwdep_info, dev); if (snd_ctl_hwdep_info(ctl_handle, hwdep_info) < 0) { if (err != -ENOENT) fprintf(stderr, "control hwdep info (%s): %s", card_id, snd_strerror(err)); continue; } if_type = snd_hwdep_info_get_iface(hwdep_info); if (if_type == SNDRV_HWDEP_IFACE_BT_SCO || if_type==12) { snd_ctl_close(ctl_handle); *devP = dev; return 0; } } } if (ctl_handle) snd_ctl_close(ctl_handle); return -1; }