]> git.alsa-project.org Git - alsa-lib.git/commitdiff
More generic support for poll descriptors
authorAbramo Bagnara <abramo@alsa-project.org>
Mon, 12 Feb 2001 23:51:49 +0000 (23:51 +0000)
committerAbramo Bagnara <abramo@alsa-project.org>
Mon, 12 Feb 2001 23:51:49 +0000 (23:51 +0000)
25 files changed:
aserver/aserver.c
include/aserver.h
include/control.h
include/header.h
include/hwdep.h
include/mixer.h
include/pcm.h
include/rawmidi.h
include/seq.h
include/timer.h
src/control/control.c
src/control/control_local.h
src/control/control_shm.c
src/control/hcontrol.c
src/hwdep/hwdep.c
src/mixer/mixer.c
src/pcm/pcm.c
src/pcm/pcm_local.h
src/pcm/pcm_multi.c
src/pcm/pcm_plugin.c
src/pcm/pcm_plugin.h
src/pcm/pcm_share.c
src/rawmidi/rawmidi.c
src/seq/seq.c
src/timer/timer.c

index d9663d9cf3ca1ab35d26bf90c5f816f89d70bb47..e15221a27c4274afe2fce9e52beba1fd06e72263 100644 (file)
@@ -276,7 +276,7 @@ int pcm_shm_open(client_t *client, int *cookie)
        if (err < 0)
                return err;
        client->device.pcm.handle = pcm;
-       client->device.pcm.fd = snd_pcm_poll_descriptor(pcm);
+       client->device.pcm.fd = _snd_pcm_poll_descriptor(pcm);
 
        shmid = shmget(IPC_PRIVATE, PCM_SHM_SIZE, 0666);
        if (shmid < 0) {
@@ -459,7 +459,7 @@ int pcm_shm_cmd(client_t *client)
                break;
        case SND_PCM_IOCTL_POLL_DESCRIPTOR:
                ctrl->result = 0;
-               return shm_ack_fd(client, snd_pcm_poll_descriptor(pcm));
+               return shm_ack_fd(client, _snd_pcm_poll_descriptor(pcm));
        case SND_PCM_IOCTL_CLOSE:
                client->ops->close(client);
                break;
@@ -503,7 +503,7 @@ int ctl_shm_open(client_t *client, int *cookie)
        if (err < 0)
                return err;
        client->device.control.handle = ctl;
-       client->device.control.fd = snd_ctl_poll_descriptor(ctl);
+       client->device.control.fd = _snd_ctl_poll_descriptor(ctl);
 
        shmid = shmget(IPC_PRIVATE, CTL_SHM_SIZE, 0666);
        if (shmid < 0) {
@@ -627,7 +627,7 @@ int ctl_shm_cmd(client_t *client)
                break;
        case SND_CTL_IOCTL_POLL_DESCRIPTOR:
                ctrl->result = 0;
-               return shm_ack_fd(client, snd_ctl_poll_descriptor(ctl));
+               return shm_ack_fd(client, _snd_ctl_poll_descriptor(ctl));
        default:
                ERROR("Bogus cmd: %x", ctrl->cmd);
                ctrl->result = -ENOSYS;
index 05242117b29b80f6504cc431ed8e0e32efa0e6a1..69076a61a8d2a7e43b93cf31875c9f05cf5c26db 100644 (file)
@@ -19,6 +19,7 @@
  */
   
 #include "../src/pcm/pcm_local.h"
+#include "../src/control/control_local.h"
 
 typedef enum _snd_dev_type {
        SND_DEV_TYPE_PCM,
index a58133f679bb796507ea0e93b58c0bb191c78e7c..8730b574bc5346a281e41010d79a0099fbcf739f 100644 (file)
@@ -159,7 +159,7 @@ int snd_ctl_open(snd_ctl_t **ctl, const char *name);
 int snd_ctl_close(snd_ctl_t *ctl);
 int snd_ctl_nonblock(snd_ctl_t *ctl, int nonblock);
 int snd_ctl_async(snd_ctl_t *ctl, int sig, pid_t pid);
-int snd_ctl_poll_descriptor(snd_ctl_t *ctl);
+int snd_ctl_poll_descriptors(snd_ctl_t *ctl, struct pollfd *pfds, unsigned int space);
 int snd_ctl_card_info(snd_ctl_t *ctl, snd_ctl_card_info_t *info);
 int snd_ctl_elem_list(snd_ctl_t *ctl, snd_ctl_elem_list_t * list);
 int snd_ctl_elem_info(snd_ctl_t *ctl, snd_ctl_elem_info_t *info);
@@ -215,7 +215,7 @@ int snd_hctl_open(snd_hctl_t **hctl, const char *name);
 int snd_hctl_close(snd_hctl_t *hctl);
 int snd_hctl_nonblock(snd_hctl_t *hctl, int nonblock);
 int snd_hctl_async(snd_hctl_t *hctl, int sig, pid_t pid);
-int snd_hctl_poll_descriptor(snd_hctl_t *hctl);
+int snd_hctl_poll_descriptors(snd_hctl_t *hctl, struct pollfd *pfds, unsigned int space);
 unsigned int snd_hctl_get_count(snd_hctl_t *hctl);
 int snd_hctl_set_compare(snd_hctl_t *hctl, snd_hctl_compare_t hsort);
 snd_hctl_elem_t *snd_hctl_first_elem(snd_hctl_t *hctl);
@@ -230,6 +230,7 @@ int snd_hctl_handle_event(snd_hctl_t *hctl, snd_ctl_event_t *event);
 int snd_hctl_handle_events(snd_hctl_t *hctl);
 const char *snd_hctl_name(snd_hctl_t *hctl);
 snd_ctl_type_t snd_hctl_type(snd_hctl_t *hctl);
+int snd_hctl_wait(snd_hctl_t *hctl, int timeout);
 
 snd_hctl_elem_t *snd_hctl_elem_next(snd_hctl_elem_t *elem);
 snd_hctl_elem_t *snd_hctl_elem_prev(snd_hctl_elem_t *elem);
index e2fa5efc80c07f6c3f730bd613ed495eeca48603..946755edde1dedea8aa0d9319f48378f283ddc12 100644 (file)
@@ -32,7 +32,7 @@
 #include <string.h>
 #include <fcntl.h>
 #include <assert.h>
-#include <sys/uio.h>
+#include <sys/poll.h>
 
 #ifndef ATTRIBUTE_UNUSED
 #define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
index 76bd43637463d4892489dd4ccc660dd2d1ea8348..4b8da59ae304aee9e379c055024b85b97911754e 100644 (file)
@@ -33,14 +33,14 @@ typedef struct _snd_hwdep snd_hwdep_t;
 extern "C" {
 #endif
 
-int snd_hwdep_open(snd_hwdep_t **handle, int card, int device, int mode);
-int snd_hwdep_close(snd_hwdep_t *handle);
-int snd_hwdep_poll_descriptor(snd_hwdep_t *handle);
-int snd_hwdep_block_mode(snd_hwdep_t *handle, int enable);
-int snd_hwdep_info(snd_hwdep_t *handle, snd_hwdep_info_t * info);
-int snd_hwdep_ioctl(snd_hwdep_t *handle, int request, void * arg);
-ssize_t snd_hwdep_write(snd_hwdep_t *handle, const void *buffer, size_t size);
-ssize_t snd_hwdep_read(snd_hwdep_t *handle, void *buffer, size_t size);
+int snd_hwdep_open(snd_hwdep_t **hwdep, int card, int device, int mode);
+int snd_hwdep_close(snd_hwdep_t *hwdep);
+int snd_hwdep_poll_descriptors(snd_hwdep_t *hwdep, struct pollfd *pfds, unsigned int space);
+int snd_hwdep_block_mode(snd_hwdep_t *hwdep, int enable);
+int snd_hwdep_info(snd_hwdep_t *hwdep, snd_hwdep_info_t * info);
+int snd_hwdep_ioctl(snd_hwdep_t *hwdep, int request, void * arg);
+ssize_t snd_hwdep_write(snd_hwdep_t *hwdep, const void *buffer, size_t size);
+ssize_t snd_hwdep_read(snd_hwdep_t *hwdep, void *buffer, size_t size);
 
 #ifdef __cplusplus
 }
index 18391286c93998e25e215b82bfc03780e64b8fee..fc47c986a1b1544c91063aedc1c7cc48c1d24e16 100644 (file)
@@ -44,8 +44,9 @@ snd_mixer_elem_t *snd_mixer_last_elem(snd_mixer_t *mixer);
 int snd_mixer_handle_events(snd_mixer_t *mixer);
 int snd_mixer_attach(snd_mixer_t *mixer, const char *name);
 int snd_mixer_detach(snd_mixer_t *mixer, const char *name);
-int snd_mixer_poll_descriptor(snd_mixer_t *mixer, const char *name);
+int snd_mixer_poll_descriptors(snd_mixer_t *mixer, struct pollfd *pfds, unsigned int space);
 int snd_mixer_load(snd_mixer_t *mixer);
+int snd_mixer_wait(snd_mixer_t *mixer, int timeout);
 int snd_mixer_set_compare(snd_mixer_t *mixer, snd_mixer_compare_t msort);
 
 snd_mixer_elem_t *snd_mixer_elem_next(snd_mixer_elem_t *elem);
index 5707aeaf6303a0bd61c83e004b01e4b38ba60dc9..920ce49ea25ccf1357b0d44345d41842a5ecab43 100644 (file)
@@ -216,7 +216,7 @@ int snd_pcm_open(snd_pcm_t **pcm, const char *name,
 
 snd_pcm_type_t snd_pcm_type(snd_pcm_t *pcm);
 int snd_pcm_close(snd_pcm_t *pcm);
-int snd_pcm_poll_descriptor(snd_pcm_t *pcm);
+int snd_pcm_poll_descriptors(snd_pcm_t *pcm, struct pollfd *pfds, unsigned int space);
 int snd_pcm_nonblock(snd_pcm_t *pcm, int nonblock);
 int snd_pcm_async(snd_pcm_t *pcm, int sig, pid_t pid);
 int snd_pcm_info(snd_pcm_t *pcm, snd_pcm_info_t *info);
index 582bb9ed20c2fd5cce689154d8644f30244a3a14..a87927eb3d75ed64c58728ebaeeab410b77c5589 100644 (file)
@@ -47,7 +47,7 @@ extern "C" {
 int snd_rawmidi_open(snd_rawmidi_t **in_rmidi, snd_rawmidi_t **out_rmidi,
                     const char *name, int mode);
 int snd_rawmidi_close(snd_rawmidi_t *rmidi);
-int snd_rawmidi_poll_descriptor(snd_rawmidi_t *rmidi);
+int snd_rawmidi_poll_descriptors(snd_rawmidi_t *rmidi, struct pollfd *pfds, unsigned int space);
 int snd_rawmidi_nonblock(snd_rawmidi_t *rmidi, int nonblock);
 int snd_rawmidi_info(snd_rawmidi_t *rmidi, snd_rawmidi_info_t * info);
 int snd_rawmidi_params(snd_rawmidi_t *rmidi, snd_rawmidi_params_t * params);
index 312b9e2393713bc76f54afda90ea59da70057604..41c44bccde621c06820589217099c47d3167537b 100644 (file)
@@ -324,7 +324,7 @@ extern "C" {
 
 int snd_seq_open(snd_seq_t **handle, const char *name, int streams, int mode);
 int snd_seq_close(snd_seq_t *handle);
-int snd_seq_poll_descriptor(snd_seq_t *handle);
+int snd_seq_poll_descriptors(snd_seq_t *handle, struct pollfd *pfds, unsigned int space);
 int snd_seq_nonblock(snd_seq_t *handle, int nonblock);
 int snd_seq_client_id(snd_seq_t *handle);
 int snd_seq_output_buffer_size(snd_seq_t *handle);
index f146f9097039b742ae806ad019b27331dad351c7..a40a28074dccabf1220cd7b0f9afb95110a55bc2 100644 (file)
@@ -50,7 +50,7 @@ extern "C" {
 
 int snd_timer_open(snd_timer_t **handle);
 int snd_timer_close(snd_timer_t *handle);
-int snd_timer_poll_descriptor(snd_timer_t *handle);
+int snd_timer_poll_descriptors(snd_timer_t *handle, struct pollfd *pfds, unsigned int space);
 int snd_timer_next_device(snd_timer_t *handle, snd_timer_id_t *tid);
 int snd_timer_select(snd_timer_t *handle, snd_timer_select_t *tselect);
 int snd_timer_info(snd_timer_t *handle, snd_timer_info_t *timer);
index b9c76075283e2bf44bd8807926c520698a0c65b7..fa62bb06dab20c79410079fbe4a5b31b0604e324 100644 (file)
@@ -68,12 +68,22 @@ int snd_ctl_async(snd_ctl_t *ctl, int sig, pid_t pid)
        return ctl->ops->async(ctl, sig, pid);
 }
 
-int snd_ctl_poll_descriptor(snd_ctl_t *ctl)
+int _snd_ctl_poll_descriptor(snd_ctl_t *ctl)
 {
        assert(ctl);
        return ctl->ops->poll_descriptor(ctl);
 }
 
+int snd_ctl_poll_descriptors(snd_ctl_t *ctl, struct pollfd *pfds, unsigned int space)
+{
+       assert(ctl);
+       if (space >= 1) {
+               pfds->fd = ctl->ops->poll_descriptor(ctl);
+               pfds->events = POLLIN;
+       }
+       return 1;
+}
+
 int snd_ctl_card_info(snd_ctl_t *ctl, snd_ctl_card_info_t *info)
 {
        assert(ctl && info);
@@ -163,8 +173,8 @@ int snd_ctl_wait(snd_ctl_t *ctl, int timeout)
 {
        struct pollfd pfd;
        int err;
-       pfd.fd = snd_ctl_poll_descriptor(ctl);
-       pfd.events = POLLIN;
+       err = snd_ctl_poll_descriptors(ctl, &pfd, 1);
+       assert(err == 1);
        err = poll(&pfd, 1, timeout);
        if (err < 0)
                return -errno;
index 5e545349c660da1ed1db86e115ae9a22e5392981..296cf04a1a7cb2824a8847244ed281aa5a8d1e22 100644 (file)
@@ -74,5 +74,6 @@ struct _snd_hctl {
 };
 
 
+int _snd_ctl_poll_descriptor(snd_ctl_t *ctl);
 int snd_ctl_hw_open(snd_ctl_t **handle, const char *name, int card);
 int snd_ctl_shm_open(snd_ctl_t **handlep, const char *name, const char *socket, const char *sname);
index 496b1371f3cf1f041025021231bf1376a473fa45..96fc5c978e25b342bfadfd1c2ef2d19969102beb 100644 (file)
@@ -34,7 +34,6 @@
 #include <netinet/in.h>
 #include <netdb.h>
 #include "aserver.h"
-#include "control_local.h"
 
 typedef struct {
        int socket;
index 2113b7e565a7b533ecc8d0b9b5b98e088ccf0cfe..e865e169d6aaaccb9a071bdc40264bbe40afd9df 100644 (file)
@@ -81,10 +81,10 @@ int snd_hctl_async(snd_hctl_t *hctl, int sig, pid_t pid)
        return snd_ctl_async(hctl->ctl, sig, pid);
 }
 
-int snd_hctl_poll_descriptor(snd_hctl_t *hctl)
+int snd_hctl_poll_descriptors(snd_hctl_t *hctl, struct pollfd *pfds, unsigned int space)
 {
        assert(hctl);
-       return snd_ctl_poll_descriptor(hctl->ctl);
+       return snd_ctl_poll_descriptors(hctl->ctl, pfds, space);
 }
 
 static int _snd_hctl_find_elem(snd_hctl_t *hctl, const snd_ctl_elem_id_t *id, int *dir)
@@ -441,6 +441,18 @@ unsigned int snd_hctl_get_count(snd_hctl_t *hctl)
        return hctl->count;
 }
 
+int snd_hctl_wait(snd_hctl_t *hctl, int timeout)
+{
+       struct pollfd pfd;
+       int err;
+       err = snd_hctl_poll_descriptors(hctl, &pfd, 1);
+       assert(err == 1);
+       err = poll(&pfd, 1, timeout);
+       if (err < 0)
+               return -errno;
+       return 0;
+}
+
 int snd_hctl_handle_event(snd_hctl_t *hctl, snd_ctl_event_t *event)
 {
        snd_hctl_elem_t *elem;
index 97f5fb3c0dc28e418144a5977e293e8241a5f192..6319515bf7ceb39fd0d85851ec2a85746f94908d 100644 (file)
@@ -42,6 +42,7 @@ int snd_hwdep_open(snd_hwdep_t **handle, int card, int device, int mode)
        int fd, ver;
        char filename[32];
        snd_hwdep_t *hwdep;
+       assert(handle);
 
        *handle = NULL;
        
@@ -77,27 +78,26 @@ int snd_hwdep_open(snd_hwdep_t **handle, int card, int device, int mode)
 int snd_hwdep_close(snd_hwdep_t *hwdep)
 {
        int res;
-
-       if (!hwdep)
-               return -EINVAL;
+       assert(hwdep);
        res = close(hwdep->fd) < 0 ? -errno : 0;
        free(hwdep);
        return res;
 }
 
-int snd_hwdep_poll_descriptor(snd_hwdep_t *hwdep)
+int snd_hwdep_poll_descriptors(snd_hwdep_t *hwdep, struct pollfd *pfds, unsigned int space)
 {
-       if (!hwdep)
-               return -EINVAL;
-       return hwdep->fd;
+       assert(hwdep);
+       if (space >= 1) {
+               pfds->fd = hwdep->fd;
+               pfds->events = POLLOUT | POLLIN;
+       }
+       return 1;
 }
 
 int snd_hwdep_block_mode(snd_hwdep_t *hwdep, int enable)
 {
        long flags;
-
-       if (!hwdep)
-               return -EINVAL;
+       assert(hwdep);
        if ((flags = fcntl(hwdep->fd, F_GETFL)) < 0)
                return -errno;
        if (enable)
@@ -111,8 +111,7 @@ int snd_hwdep_block_mode(snd_hwdep_t *hwdep, int enable)
 
 int snd_hwdep_info(snd_hwdep_t *hwdep, snd_hwdep_info_t *info)
 {
-       if (!hwdep || !info)
-               return -EINVAL;
+       assert(hwdep && info);
        if (ioctl(hwdep->fd, SNDRV_HWDEP_IOCTL_INFO, info) < 0)
                return -errno;
        return 0;
@@ -120,8 +119,7 @@ int snd_hwdep_info(snd_hwdep_t *hwdep, snd_hwdep_info_t *info)
 
 int snd_hwdep_ioctl(snd_hwdep_t *hwdep, int request, void * arg)
 {
-       if (!hwdep)
-               return -EINVAL;
+       assert(hwdep);
        if (ioctl(hwdep->fd, request, arg) < 0)
                return -errno;
        return 0;
@@ -130,9 +128,7 @@ int snd_hwdep_ioctl(snd_hwdep_t *hwdep, int request, void * arg)
 ssize_t snd_hwdep_write(snd_hwdep_t *hwdep, const void *buffer, size_t size)
 {
        ssize_t result;
-
-       if (!hwdep || (!buffer && size > 0))
-               return -EINVAL;
+       assert(hwdep && (buffer || size == 0));
        result = write(hwdep->fd, buffer, size);
        if (result < 0)
                return -errno;
@@ -142,9 +138,7 @@ ssize_t snd_hwdep_write(snd_hwdep_t *hwdep, const void *buffer, size_t size)
 ssize_t snd_hwdep_read(snd_hwdep_t *hwdep, void *buffer, size_t size)
 {
        ssize_t result;
-
-       if (!hwdep || (!buffer && size > 0))
-               return -EINVAL;
+       assert(hwdep && (buffer || size == 0));
        result = read(hwdep->fd, buffer, size);
        if (result < 0)
                return -errno;
index 0f8d76633345183e73cdaf969d455a03bf28d1d5..8db19832aa843abdce38a0dee85358a18fc4dfe6 100644 (file)
@@ -447,19 +447,48 @@ int snd_mixer_set_compare(snd_mixer_t *mixer, snd_mixer_compare_t msort)
        return 0;
 }
 
-int snd_mixer_poll_descriptor(snd_mixer_t *mixer, const char *name)
+int snd_mixer_poll_descriptors(snd_mixer_t *mixer, struct pollfd *pfds, unsigned int space)
 {
        struct list_head *pos, *next;
-       assert(mixer && name);
+       unsigned int count = 0;
+       assert(mixer);
        list_for_each(pos, next, &mixer->slaves) {
                snd_mixer_slave_t *s;
-               const char *n;
+               int n;
                s = list_entry(pos, snd_mixer_slave_t, list);
-               n = snd_hctl_name(s->hctl);
-               if (n && strcmp(name, n) == 0)
-                       return snd_hctl_poll_descriptor(s->hctl);
+               n = snd_hctl_poll_descriptors(s->hctl, pfds, space);
+               if (n < 0)
+                       return n;
+               count += n;
+               if (space > (unsigned int) n) {
+                       space -= n;
+                       pfds += n;
+               } else
+                       space = 0;
        }
-       return -ENOENT;
+       return count;
+}
+
+int snd_mixer_wait(snd_mixer_t *mixer, int timeout)
+{
+       struct pollfd spfds[16];
+       struct pollfd *pfds = spfds;
+       int err;
+       int count;
+       count = snd_mixer_poll_descriptors(mixer, pfds, sizeof(spfds) / sizeof(spfds[0]));
+       if (count < 0)
+               return count;
+       if ((unsigned int) count > sizeof(spfds) / sizeof(spfds[0])) {
+               pfds = malloc(count * sizeof(*pfds));
+               if (!pfds)
+                       return -ENOMEM;
+               err = snd_mixer_poll_descriptors(mixer, pfds, count);
+               assert(err == count);
+       }
+       err = poll(pfds, count, timeout);
+       if (err < 0)
+               return -errno;
+       return 0;
 }
 
 snd_mixer_elem_t *snd_mixer_first_elem(snd_mixer_t *mixer)
index f7395561120a7c9c565a6a5de71eded91a375de2..d868eef256dbd499af9f192a59a0657c5ca983ed 100644 (file)
@@ -205,12 +205,12 @@ snd_pcm_sframes_t snd_pcm_readn(snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t s
 }
 
 /* FIXME */
-#define snd_pcm_link_descriptor snd_pcm_poll_descriptor
+#define _snd_pcm_link_descriptor _snd_pcm_poll_descriptor
 
 int snd_pcm_link(snd_pcm_t *pcm1, snd_pcm_t *pcm2)
 {
-       int fd1 = snd_pcm_link_descriptor(pcm1);
-       int fd2 = snd_pcm_link_descriptor(pcm2);
+       int fd1 = _snd_pcm_link_descriptor(pcm1);
+       int fd2 = _snd_pcm_link_descriptor(pcm2);
        if (fd1 < 0 || fd2 < 0)
                return -ENOSYS;
        if (ioctl(fd1, SNDRV_PCM_IOCTL_LINK, fd2) < 0) {
@@ -223,7 +223,7 @@ int snd_pcm_link(snd_pcm_t *pcm1, snd_pcm_t *pcm2)
 int snd_pcm_unlink(snd_pcm_t *pcm)
 {
        int fd;
-       fd = snd_pcm_link_descriptor(pcm);
+       fd = _snd_pcm_link_descriptor(pcm);
        if (ioctl(fd, SNDRV_PCM_IOCTL_UNLINK) < 0) {
                SYSERR("SNDRV_PCM_IOCTL_UNLINK failed");
                return -errno;
@@ -231,12 +231,22 @@ int snd_pcm_unlink(snd_pcm_t *pcm)
        return 0;
 }
 
-int snd_pcm_poll_descriptor(snd_pcm_t *pcm)
+int _snd_pcm_poll_descriptor(snd_pcm_t *pcm)
 {
        assert(pcm);
        return pcm->poll_fd;
 }
 
+int snd_pcm_poll_descriptors(snd_pcm_t *pcm, struct pollfd *pfds, unsigned int space)
+{
+       assert(pcm);
+       if (space >= 1) {
+               pfds->fd = pcm->poll_fd;
+               pfds->events = pcm->stream == SND_PCM_STREAM_PLAYBACK ? POLLOUT : POLLIN;
+       }
+       return 1;
+}
+
 #define STATE(v) [SND_PCM_STATE_##v] = #v
 #define STREAM(v) [SND_PCM_STREAM_##v] = #v
 #define READY(v) [SND_PCM_READY_##v] = #v
@@ -688,8 +698,8 @@ int snd_pcm_wait(snd_pcm_t *pcm, int timeout)
 {
        struct pollfd pfd;
        int err;
-       pfd.fd = snd_pcm_poll_descriptor(pcm);
-       pfd.events = pcm->stream == SND_PCM_STREAM_PLAYBACK ? POLLOUT : POLLIN;
+       err = snd_pcm_poll_descriptors(pcm, &pfd, 1);
+       assert(err == 1);
        err = poll(&pfd, 1, timeout);
        if (err < 0)
                return -errno;
index 97466a7dd148ea7c6742439ca7a1fd6408da0774..ec2ecd5fb28d29b7358813d80f28b891a8b78f31 100644 (file)
@@ -202,6 +202,7 @@ snd_pcm_sframes_t snd_pcm_read_mmap(snd_pcm_t *pcm, snd_pcm_uframes_t size);
 snd_pcm_sframes_t snd_pcm_write_mmap(snd_pcm_t *pcm, snd_pcm_uframes_t size);
 int snd_pcm_channel_info(snd_pcm_t *pcm, snd_pcm_channel_info_t *info);
 int snd_pcm_channel_info_shm(snd_pcm_t *pcm, snd_pcm_channel_info_t *info, int shmid);
+int _snd_pcm_poll_descriptor(snd_pcm_t *pcm);
 
 static inline snd_pcm_uframes_t snd_pcm_mmap_playback_avail(snd_pcm_t *pcm)
 {
index 4af4151fdef42fe8bf767510e27934447ed32dde..0576aa7c82d2e7418646fd06530ca0951cf2bf61 100644 (file)
@@ -447,7 +447,7 @@ int snd_pcm_multi_poll_descriptor(snd_pcm_t *pcm)
 {
        snd_pcm_multi_t *multi = pcm->private_data;
        snd_pcm_t *slave = multi->slaves[0].pcm;
-       return snd_pcm_poll_descriptor(slave);
+       return _snd_pcm_poll_descriptor(slave);
 }
 
 static void snd_pcm_multi_dump(snd_pcm_t *pcm, snd_output_t *out)
index 4d4c7774e365e4f9e3f916a923850252a4d7fda6..cb7a7af7c72d55ce4b94f03d89d19854e9b51c06 100644 (file)
@@ -337,7 +337,7 @@ int snd_pcm_plugin_munmap(snd_pcm_t *pcm)
 int snd_pcm_plugin_poll_descriptor(snd_pcm_t *pcm)
 {
        snd_pcm_plugin_t *plugin = pcm->private_data;
-       return snd_pcm_poll_descriptor(plugin->slave);
+       return _snd_pcm_poll_descriptor(plugin->slave);
 }
 
 int snd_pcm_plugin_hw_refine_slave(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
index a0856187006ab7a415a222c9a4206744589a6b97..7d6a0375163e5a43f90e68bb87ce924384ac6d5f 100644 (file)
@@ -61,7 +61,7 @@ int snd_pcm_plugin_mmap(snd_pcm_t *pcm);
 int snd_pcm_plugin_munmap_status(snd_pcm_t *pcm);
 int snd_pcm_plugin_munmap_control(snd_pcm_t *pcm);
 int snd_pcm_plugin_munmap(snd_pcm_t *pcm);
-int snd_pcm_plugin_poll_descriptor(snd_pcm_t *pcm);
+int snd_pcm_plugin_poll_descriptors(snd_pcm_t *pcm, struct pollfd *pfds, unsigned int space);
 int snd_pcm_plugin_hw_params_slave(snd_pcm_t *pcm, snd_pcm_hw_params_t *params);
 int snd_pcm_plugin_hw_refine_slave(snd_pcm_t *pcm, snd_pcm_hw_params_t *params);
 
index 00b535c1b2d66400b85850a0ca3984c1fd329050..11b2c232910843c5ba62da8f721131319b12ee5c 100644 (file)
@@ -346,8 +346,8 @@ void *snd_pcm_share_slave_thread(void *data)
        int err;
        pfd[0].fd = slave->poll[0];
        pfd[0].events = POLLIN;
-       pfd[1].fd = snd_pcm_poll_descriptor(spcm);
-       pfd[1].events = POLLIN | POLLOUT;
+       err = snd_pcm_poll_descriptors(spcm, &pfd[1], 1);
+       assert(err == 1);
        Pthread_mutex_lock(&slave->mutex);
        err = pipe(slave->poll);
        assert(err >= 0);
index 32f608a75d94577892f40bf07267c5511cd9409b..e22aa06c0774dd944aff99371cddd195afeaa1c6 100644 (file)
@@ -52,12 +52,23 @@ int snd_rawmidi_close(snd_rawmidi_t *rmidi)
        return 0;
 }
 
-int snd_rawmidi_poll_descriptor(snd_rawmidi_t *rmidi)
+int _snd_rawmidi_poll_descriptor(snd_rawmidi_t *rmidi)
 {
        assert(rmidi);
        return rmidi->poll_fd;
 }
 
+int snd_rawmidi_poll_descriptors(snd_rawmidi_t *rmidi, struct pollfd *pfds, unsigned int space)
+{
+       assert(rmidi);
+       if (space >= 1) {
+               pfds->fd = rmidi->poll_fd;
+               pfds->events = rmidi->stream == SND_RAWMIDI_STREAM_OUTPUT ? POLLOUT : POLLIN;
+       }
+       return 1;
+}
+
+
 int snd_rawmidi_nonblock(snd_rawmidi_t *rmidi, int nonblock)
 {
        int err;
index e45aa985204b10b50a50293789fa755fb0cf7979..830846aecb9853d1019fc189ea68f1bfc402b9de 100644 (file)
@@ -146,12 +146,26 @@ int snd_seq_close(snd_seq_t *seq)
 /*
  * returns the file descriptor of the client
  */
-int snd_seq_poll_descriptor(snd_seq_t *seq)
+int _snd_seq_poll_descriptor(snd_seq_t *seq)
 {
        assert(seq);
        return seq->poll_fd;
 }
 
+int snd_seq_poll_descriptors(snd_seq_t *seq, struct pollfd *pfds, unsigned int space)
+{
+       assert(seq);
+       if (space >= 1) {
+               pfds->fd = seq->poll_fd;
+               pfds->events = 0;
+               if (seq->streams & SND_SEQ_OPEN_INPUT)
+                       pfds->events |= POLLIN;
+               if (seq->streams & SND_SEQ_OPEN_OUTPUT)
+                       pfds->events |= POLLOUT;
+       }
+       return 1;
+}
+
 /*
  * set blocking behavior
  */
index 45b701d1af27d7c2b8d9c18081e7f9c409e6ae90..9a1fff68350def596c0b8af64ef9c58a48d6fdb6 100644 (file)
@@ -74,7 +74,7 @@ int snd_timer_close(snd_timer_t *handle)
        return res;
 }
 
-int snd_timer_poll_descriptor(snd_timer_t *handle)
+int _snd_timer_poll_descriptor(snd_timer_t *handle)
 {
        snd_timer_t *tmr;
 
@@ -84,6 +84,16 @@ int snd_timer_poll_descriptor(snd_timer_t *handle)
        return tmr->fd;
 }
 
+int snd_timer_poll_descriptors(snd_timer_t *timer, struct pollfd *pfds, unsigned int space)
+{
+       assert(timer);
+       if (space >= 1) {
+               pfds->fd = timer->fd;
+               pfds->events = POLLIN;
+       }
+       return 1;
+}
+
 int snd_timer_next_device(snd_timer_t *handle, snd_timer_id_t * tid)
 {
        snd_timer_t *tmr;