summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2011-05-27 13:49:34 (GMT)
committerTakashi Iwai <tiwai@suse.de>2011-05-27 13:49:34 (GMT)
commit7fb12ca79b96d791119c20a5a3ad4d14fd97b49e (patch)
treee420bcec8a6d98dad23b1827abd0618d9ea99852
parenta4bb25877aac014137d9ded9ac214e1d0e8dd990 (diff)
downloadsalsa-lib-7fb12ca79b96d791119c20a5a3ad4d14fd97b49e.tar.gz
salsa-lib-7fb12ca79b96d791119c20a5a3ad4d14fd97b49e.tar.xz
Refactoring pcm subdev assigment
-rw-r--r--src/pcm.c29
1 files changed, 16 insertions, 13 deletions
diff --git a/src/pcm.c b/src/pcm.c
index dfeda6c..f5c2128 100644
--- a/src/pcm.c
+++ b/src/pcm.c
@@ -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));