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) {
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;
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) {
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;
*/
#include "../src/pcm/pcm_local.h"
+#include "../src/control/control_local.h"
typedef enum _snd_dev_type {
SND_DEV_TYPE_PCM,
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);
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);
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);
#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__))
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
}
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);
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);
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);
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);
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);
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);
{
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;
};
+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);
#include <netinet/in.h>
#include <netdb.h>
#include "aserver.h"
-#include "control_local.h"
typedef struct {
int socket;
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)
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;
int fd, ver;
char filename[32];
snd_hwdep_t *hwdep;
+ assert(handle);
*handle = NULL;
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)
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;
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;
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;
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;
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)
}
/* 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) {
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;
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
{
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;
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)
{
{
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)
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)
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);
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);
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;
/*
* 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
*/
return res;
}
-int snd_timer_poll_descriptor(snd_timer_t *handle)
+int _snd_timer_poll_descriptor(snd_timer_t *handle)
{
snd_timer_t *tmr;
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;