diff options
author | Takashi Iwai <tiwai@suse.de> | 2011-05-27 15:49:34 +0200 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2011-05-27 15:49:34 +0200 |
commit | 7fb12ca79b96d791119c20a5a3ad4d14fd97b49e (patch) | |
tree | e420bcec8a6d98dad23b1827abd0618d9ea99852 | |
parent | a4bb25877aac014137d9ded9ac214e1d0e8dd990 (diff) | |
download | salsa-lib-7fb12ca79b96d791119c20a5a3ad4d14fd97b49e.tar.gz |
Refactoring pcm subdev assigment
-rw-r--r-- | src/pcm.c | 29 |
1 files changed, 16 insertions, 13 deletions
@@ -40,11 +40,19 @@ static void snd_pcm_hw_munmap_status(snd_pcm_t *pcm); * open/close */ +static int get_pcm_subdev(int fd) +{ + snd_pcm_info_t info; + memzero_valgrind(&info, sizeof(info)); + if (ioctl(fd, SNDRV_PCM_IOCTL_INFO, &info) < 0) + return -errno; + return info.subdevice; +} + /* open the substream with the given subdevice number */ static int open_with_subdev(const char *filename, int fmode, int card, int subdev) { - snd_pcm_info_t info; snd_ctl_t *ctl; int err, fd; @@ -60,15 +68,12 @@ static int open_with_subdev(const char *filename, int fmode, if (fd < 0) return -errno; - memzero_valgrind(&info, sizeof(info)); - if (ioctl(fd, SNDRV_PCM_IOCTL_INFO, &info) >= 0 && - info.subdevice == subdev) { - snd_ctl_close(ctl); - return fd; + if (get_pcm_subdev(fd) != subdev) { + close(fd); + fd = -EBUSY; } - close(fd); snd_ctl_close(ctl); - return -EBUSY; + return fd; } int snd_pcm_open(snd_pcm_t **pcmp, const char *name, @@ -111,13 +116,11 @@ int snd_pcm_open(snd_pcm_t **pcmp, const char *name, goto error; } if (subdev < 0) { - snd_pcm_info_t info; - memzero_valgrind(&info, sizeof(info)); - if (ioctl(fd, SNDRV_PCM_IOCTL_INFO, &info) < 0) { - err = -errno; + subdev = get_pcm_subdev(fd); + if (subdev < 0) { + err = subdev; goto error; } - subdev = info.subdevice; } pcm = calloc(1, sizeof(*pcm)); |